Un exemple simple
Comme entrée en matière avec gtkmm, nous débuterons avec le programme le plus simple qui soit. Ce programme crée une fenêtre vide de 200 x 200 pixels.
File: base.cc (For use with gtkmm 3, not gtkmm 2)
#include <gtkmm.h> int main(int argc, char *argv[]) { auto app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base"); Gtk::Window window; window.set_default_size(200, 200); return app->run(window); }
Détaillons maintenant chaque ligne de l'exemple
#include <gtkmm.h>
Tous les programmes gtkmm doivent inclure certains fichiers d'en-tête gtkmm ; gtkmm.h inclut la totalité du jeu d'en-têtes gtkmm. En règle générale, ce n'est pas une bonne idée parce que cette façon de faire inclut à peu près un mégaoctet d'en-têtes, mais pour des programmes simples, c'est acceptable.
The next statement:
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");
The next two lines of code create a window and set its default (initial) size:
Gtk::Window window; window.set_default_size(200, 200);
The last line shows the window and enters the gtkmm main processing loop, which will finish when the window is closed. Your main() function will then return with an appropriate success or error code.
return app->run(window);
After putting the source code in simple.cc you can compile the above program with gcc using:
g++ simple.cc -o simple `pkg-config gtkmm-3.0 --cflags --libs`