Einfaches Beispiel
Am Anfang unserer Einführung in gtkmm beginnen wir mit dem einfachsten möglichen Programm. Es erzeugt ein leeres, 200 mal 200 Pixel großes Fenster.
File: base.cc (For use with gtkmm 3, not gtkmm 2)
#include <gtkmm.h> int main(int argc, char *argv[]) { Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base"); Gtk::ApplicationWindow window; return app->run(window); }
Erklärung der einzelnen Zeilen des Beispiels
#include <gtkmm.h>
All gtkmm programs must include certain gtkmm headers; gtkmm.h includes the entire gtkmm kit. This is usually not a good idea, because it includes a megabyte or so of headers, but for simple programs, it suffices.
The next line:
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");
Die nächsten zwei Codezeilen erzeugen ein Fenster und stellen es dar:
Gtk::Window window;
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`