GTK implementation of MessageBox

前端 未结 3 1230
悲哀的现实
悲哀的现实 2020-12-30 19:37

I have been trying to implement Win32\'s MessageBox using GTK. The app uses SDL/OpenGL, so this isn\'t a GTK app.

I handle the initialization (gtk_

3条回答
  •  感动是毒
    2020-12-30 20:08

    To manage a dialog box with GTK+, use a GtkDialog and gtk_dialog_run() instead of managing a window and a main loop by yourself.

    EDIT / ADDENDUM :

    What I mean is "just use" : I don't understand why you create a windows you never use and a main loop which seems useless (at least from the piece of code you posted). You can write something as short as :

    int MessageBox(HWND hwnd, const char* text, const char* caption, UINT type)
    {
        GtkWidget *dialog ;
    
        /* Instead of 0, use GTK_DIALOG_MODAL to get a modal dialog box */
    
        if (type & MB_YESNO)
            dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, text );
        else
            dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, text );
    
    
        gtk_window_set_title(GTK_WINDOW(dialog), caption);
        gint result = gtk_dialog_run(GTK_DIALOG(dialog));
        gtk_widget_destroy( GTK_WIDGET(dialog) );
    
        if (type & MB_YESNO)
        {
            switch (result)
            {
            default:
            case GTK_RESPONSE_DELETE_EVENT:
            case GTK_RESPONSE_NO:
                return IDNO;
            case GTK_RESPONSE_YES:
                return IDYES;
            }
            return IDOK;
        } 
    }
    

提交回复
热议问题