1. Gtkmm学习资源
- Gnome Projects
https://wiki.gnome.org/Projects
https://wiki.gnome.org/Projects/gtkmm - gtkmm: C++ Interfaces for GTK and GNOME
https://gtkmm.org/en/
https://developer-old.gnome.org/gtkmm-tutorial/stable/sec-gtkmm.html.zh_CN - Programming with gtkmm
https://developer-old.gnome.org/gtkmm-tutorial/ - gtkmm on Microsoft Windows
https://wiki.gnome.org/Projects/gtkmm/MSWindows - gtkmm-documentation(github文档,有examples)
https://gitlab.gnome.org/GNOME/gtkmm-documentation/-/tree/master/
2. CB20.03+Gtkmm-3.0+MSYS2
- 安装参考网址: https://wiki.gnome.org/Projects/gtkmm/MSWindows
- CB20.03配置和Gtk在CB中的配置过程一样,首先使用pkg-config查寻gtkmm编译依赖相关信息:
# pkg-config --cflags gtkmm-3.0 |xargs -n1
# pkg-config --libs gtkmm-3.0 |xargs -n2
然后,在CB中新建一个基于C++语言的项目,并打开项目的
Build options...
进行以下配置:
1. Other compiler options
2. Linker settings
3. Search directories
3. Hello,Gtkmm
#include <gtkmm.h>
int main(int argc, char** argv)
{
auto app = Gtk::Application::create(argc, argv);
Gtk::Window window;
window.set_title("Hello,Gtkmm..");
window.set_default_size(400,300);
return app->run(window);
}
4. 一个带点击事件的简单按钮窗口
#include <gtkmm/window.h>
#include <gtkmm/button.h>
#include <gtkmm/application.h>
#include <iostream>
class Buttons : public Gtk::Window
{
public:
Buttons();
virtual ~Buttons();
protected:
//Signal handlers:
void on_button_clicked();
//Child widgets:
Gtk::Button m_button;
};
Buttons::Buttons()
{
m_button.add_pixlabel("info.xpm", "cool button");
set_title("Pixmap'd buttons!");
set_border_width(10);
set_default_size(280,40);
set_position(Gtk::WIN_POS_CENTER);
m_button.signal_clicked().connect( sigc::mem_fun(*this, &Buttons::on_button_clicked) );
add(m_button);
show_all_children();
}
Buttons::~Buttons(){ }
void Buttons::on_button_clicked()
{
std::cout << "The Button is clicked" << std::endl;
}
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example");
Buttons buttons;
//Shows the window and returns when it is closed.
return app->run(buttons);
}