The event flow of the GTK + program when the main window is closed

Source: Internet
Author: User
Tags gtk

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.