This code is taken from my website:
Gnome Programming Tutorial: Simple Gnome Application Using libglade and C/GTK+
This code is a very basic Gnome application. The entire tarball with the glade file and the configure script can be downloaded here:
gnome3-0.1.tar.gz
Code:
/* the config.h file generated by the autotools */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/* this will hold the path to the glade file after the "make install" */
#define GLADE_FILE PACKAGE_DATA_DIR"/gnome3/gnome3.glade"
#include <gnome.h>
#include <glade/glade.h>
/* callback function prototypes */
static gint delete_event_cb(GtkWidget* w, GdkEventAny* e, gpointer data);
static gint destroy_cb(GtkWidget* w, GdkEventAny* e, gpointer data);
int main (int argc, char *argv[])
{
GtkWidget *app_window; /* main application window widget */
GladeXML *gxml; /* glade xml file */
/* initialize libgnome */
gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE,
argc, argv,
NULL);
/* create GladeXML object and connect signals */
gxml = glade_xml_new (GLADE_FILE, NULL, NULL);
glade_xml_signal_autoconnect (gxml);
/* get the app_window from the glade XML file */
app_window = glade_xml_get_widget (gxml, "app_window");
/* Connect signals for termination of application */
g_signal_connect(G_OBJECT(app_window), "delete_event",
G_CALLBACK(delete_event_cb), NULL);
g_signal_connect(G_OBJECT(app_window), "destroy",
G_CALLBACK(destroy_cb), NULL);
/* show the main window */
gtk_widget_show (app_window);
/* begin main GTK loop */
gtk_main ();
return 0;
}
static gint delete_event_cb(GtkWidget* w, GdkEventAny* e, gpointer data)
{
/* callback for "delete" signal */
g_print("main.c:delete_event_cb()\n");
return 0;
}
static gint destroy_cb(GtkWidget* w, GdkEventAny* e, gpointer data)
{
/* callback for "destroy" signal */
g_print("main.c:destroy_cb()\n");
/* quit application */
gtk_main_quit();
return 0;
}
void
on_toolbutton_new_clicked(GtkWidget *w, GdkEventKey *e)
{
/* the 'New' toolbar was clicked */
g_print("main.c:on_toolbutton_new_clicked()");
}