How do I add a popup menu to my GTK+ application?

GTK+ FAQ
<<< Previous | Development with GTK+: general questions | Next >>>

# How do I add a popup menu to my GTK+ application?

The `menu` example in the examples/menu directory of the GTK+ distribution implements a popup menu with this technique:

    static gint button_press (GtkWidget *widget, GdkEvent *event)
    {

        if (event->type == GDK_BUTTON_PRESS) {
            GdkEventButton *bevent = (GdkEventButton *) event;
            gtk_menu_popup (GTK_MENU(widget), NULL, NULL, NULL, NULL,
                            bevent->button, bevent->time);
            /* Tell calling code that we have handled this event; the buck
             * stops here. */
            return TRUE;
        }

        /* Tell calling code that we have not handled this event; pass it on. */
        return FALSE;
    }

<<< Previous | Home | Next >>>
How do I set the size of a widget/window? How do I prevent the user resizing my window? [GTK 2.x] | Up | How do I disable or enable a widget, such as a button?