Copyright (C) 2000-2012 |
GNU Info (gtk.info)SimpleThe simplest GTK program ======================== The 16 line GTK program shown below is just about the simplest possible program which uses GTK. (Well, technically, you don't have to create the window and it would still be a program which uses GTK). The program, when compiled and run, will create a single window 200x200 pixels in size. The program does not exit until its is explicitly killed using the shell or a window manager function. #include <gtk/gtk.h> int main (int argc, char *argv[]) { GtkWidget *window; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_show (window); gtk_main (); return 0; } The first point of interest in this program is the standard initialization line. gtk_init (&argc, &argv); Almost every GTK program will contain such a line. GTK will initialize itself and GDK and remove any command line arguments it recognizes from ARGC and ARGV. The next two lines of code create and display a window. window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_show (window); The `GTK_WINDOW_TOPLEVEL' argument specifies that we want the window to undergo window manager decoration and placement. One might be lead to think that the window, since it has no children, would be 0x0 pixels in size. But, this is not the case because a window that has no children defaults to 200x200 pixels in size. Mainly because 0x0 windows are annoying to manipulate or even see in some cases. The last line enters the GTK main processing loop. gtk_main (); Normally, `gtk_main' is called once and the program should exit when it returns. Note: Initialization and exit. |