When the mouse clicks the Close button of the GTK + window, the program first receives the Delete_event, and when the event handler returns True, the event is handled to prevent further propagation, thereby canceling the shutdown; When false is returned, the event message propagates further up, and the GTK + The default handler function, which produces the Destroy event, which is typically closed with gtk_main_quit in the handler function of the event, when the Gtk_main () message loop exits, and the program exits.
Here is the sample code:
#include <gnome.h>
gboolean delete_handle (gtkwidget *self,gdkevent *event,gpointer data) {
static gint Count = 0;
G_print ("Attempt number%d\n", ++count);
if (count>2) return FALSE;
return TRUE;
}
Gboolean destroy_handle (gtkwidget *self,gdkevent *event,gpointer data) {
g_print ("shutting down\n");
Gtk_main_quit ();
return FALSE;
}
int main (int argc,char **argv) {
gtkwidget *w;
Gtk_init (&ARGC,&ARGV);
W = gtk_window_new (gtk_window_toplevel);
Gtk_signal_connect (Gtk_object (w), "Delete_event", G_callback (Delete_handle), NULL);
Gtk_signal_connect (Gtk_object (W), "Destroy", G_callback (Destroy_handle), NULL);
Gtk_widget_show_all (w);
Gtk_main ();
return 0;
}
The Compile connection command is:
Clang ' pkg-config--cflags--libs libgnomeui-2.0 '-o3-g-s-o destroy DESTROY.C