title: GTK implementation of MessageBox
body: <p>I have been trying to implement Win32's <code>MessageBox</code> using GTK. The app uses SDL/OpenGL, so this isn't a GTK app.</p>
  <p>I handle the initialization (<code>gtk_init</code>) sort of stuff inside the <code>MessageBox</code> function as follows:</p>
  <pre><code>int MessageBox(HWND hwnd, const char* text, const char* caption, UINT type)
  {
      GtkWidget *window = NULL;
      GtkWidget *dialog = NULL;
  
      gtk_init(&amp;gtkArgc, &amp;gtkArgv);
      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      g_signal_connect(G_OBJECT(window), &quot;delete_event&quot;, G_CALLBACK(delete_event), NULL);
      g_signal_connect(G_OBJECT(window), &quot;destroy&quot;, G_CALLBACK(destroy), NULL);
      // gcallback calls gtk_main_quit()
      gtk_init_add((GtkFunction)gcallback, NULL);
  
      if (type &amp; MB_YESNO) {
          dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, text);
      } else {
          dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, text);
      }
  
      gtk_window_set_title(GTK_WINDOW(dialog), caption);
      gint result = gtk_dialog_run(GTK_DIALOG(dialog));
  
      gtk_main();
  
      gtk_widget_destroy(dialog);
  
      if (type &amp; MB_YESNO) {
          switch (result) {
          default:
          case GTK_RESPONSE_DELETE_EVENT:
          case GTK_RESPONSE_NO:
              return IDNO;
              break;
          case GTK_RESPONSE_YES:
              return IDYES;
              break;
          }
      }
  
      return IDOK;
  } 
  </code></pre>
  <p>Now, I am by no means an experienced GTK programmer, and I realize that I'm probably doing something horribly wrong.</p>
  <p>However, my problem is that the last dialog popped up with this function staying around until the process exits. Any ideas?</p>