Einfaches Beispiel
To begin our introduction to gtkmm, we'll start with the simplest program possible. This program will create an empty 200 x 200 pixel window.
File: base.cc (For use with gtkmm 2, not gtkmm 3)
#include <gtkmm.h> int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); Gtk::Window window; Gtk::Main::run(window); return 0; }
We will now explain each line of the example
#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:
Gtk::Main kit(argc, argv);
The next two lines of code create and display a window:
Gtk::Window window;
The last line shows the window and enters the gtkmm main processing loop, which will finish when the window is closed.
Gtk::Main::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-2.4 --cflags --libs`