Simple Dialog Boxes with C/GTK+ and libglade
March 9, 2006
This is a simple Linux application using GTK+ and libglade to demonstrate some very simple dialog boxes. The application's interface is created in Glade and accessed using libglade, however, the dialog boxes are implemented entirely in GTK+ code since they're so easy to implement that way. These dialog boxes are from the GtkMessageDialog widget, which is a derivative of the GtkDialog widget.

You may wonder why I'm using libglade at all for this. The reason is to promote the use of libglade and show examples of how libglade can be used in combination with C/GTK+ generated widgets.
Information Dialog |
Warning Dialog |
Error Dialog |
Question Dialog |
Compiling the Project
Download the glade file (gui.glade) and the source code (main.c) here: dialogs1.tar.gz On my machine, the code was compiled with: gcc -o dialogs -Wall -g main.c `pkg-config gtk+-2.0 --cflags --libs `-I/usr/include/libglade-2.0 -lglade-2.0 You may have to modify the include path for your distribution's location of libglade. I also have the code written such that the glade file gui.glade must exist in the same path as the executable.Connecting the Signals
I'm defining the signals in the glade file, however, I'm connecting them individually as opposed to using glade_xml_signal_autoconnect(). The reason for this is because I simply have gotten in the habbit of doing so. In this case, some, but not all of the signals have user data passed to them. For example:glade_xml_signal_connect_data (gxml, "on_info_button_clicked",
G_CALLBACK(on_info_button_clicked), main_window);
In this case, the main_window, which is a pointer to my main window, is being passed as user data to the callback function. This allows me to setup the message box with the main_window as the "parent" for the dialog box.
GtkResponseType, GtkButtonsType, and GtkMessageType
You may notice that I'm declaring variables as the above types. These are all enums (gint) as described in the documentation for GtkMessageDialog and GtkDialog. It makes the code a bit more "readable".
Categories:
GTK+ Programming
Copyright © 2004 - 2010 Micah Carrick. All Rights Reserved.
Information Dialog
Warning Dialog
Error Dialog
Question Dialog
1 Comments about "Simple Dialog Boxes with C/GTK+ and libglade"
RSS Feed
Could you point me in the direction of creating a drag and drop interface for converting files? I want the interface to have multi columns so the left would be where the user can make choices based on the file file dimensions etc...The right column would be where the file would be dragged into and it would allow dragging multiple files . Pretty much a skeleton example but with working code would be great. I am in a desperate hurry to get something like that created for a project. I am using GTK to build the interface, and C to write the code to make it come alive.
Thank you very much for your time!
-Brian
Leave a Comment about "Simple Dialog Boxes with C/GTK+ and libglade"