GTK implementation of MessageBox

前端 未结 3 1206
悲哀的现实
悲哀的现实 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:13

    A few things:

    You are creating (and not using) an unnecessary toplevel window, named window. You can just delete these lines:

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event), NULL);
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
    

    Also, the flow doesn't seem quite right. gtk_main() starts the GTK main loop, which blocks until something exits it. gtk_dialog_run() also starts a main loop, but it exits as soon as one of the buttons is clicked.

    I think it might be enough for you to remove the gtk_init_add() and gtk_main() calls, and simply deal with the return value. Also the gtk_widget_destroy() call is unnecessary, as the dialog window is automatically destroyed when gtk_dialog_run() returns.

提交回复
热议问题