Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 33633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:57:06+00:00 2026-05-10T13:57:06+00:00

I have been trying to implement Win32’s MessageBox using GTK. The app uses SDL/OpenGL,

  • 0

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_init) sort of stuff inside the MessageBox function as follows:

int MessageBox(HWND hwnd, const char* text, const char* caption, UINT type) {     GtkWidget *window = NULL;     GtkWidget *dialog = NULL;      gtk_init(&gtkArgc, &gtkArgv);     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);     // gcallback calls gtk_main_quit()     gtk_init_add((GtkFunction)gcallback, NULL);      if (type & 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 & 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; }  

Now, I am by no means an experienced GTK programmer, and I realize that I’m probably doing something horribly wrong.

However, my problem is that the last dialog popped up with this function staying around until the process exits. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:57:07+00:00Added an answer on May 10, 2026 at 1:57 pm

    Hmm, ok. I’d suggest code like this, then:

    typedef struct {     int type;     int result; } DialogData;      static gboolean display_dialog(gpointer user_data) {     DialogData *dialog_data = user_data;     GtkWidget *dialog;          if (dialog_data->type & MB_YESNO)         dialog = gtk_message_dialog_new(...);     else         dialog = gtk_message_dialog_new(...);          // Set title, etc.          dialog_data->result = gtk_dialog_run(...);          gtk_main_quit();  // Quits the main loop run in MessageBox()          return FALSE; }      int MessageBox(...) {     DialogData dialog_data;          dialog_data.type = type;          gtk_idle_add(display_dialog, &dialog_data);          gtk_main();          // Do stuff based on dialog_data.result } 

    The struct is required because you need to pass around a couple pieces of data. The gtk_idle_add() call adds a method to be run when the main loop is running and idle, and the FALSE return value from the display_dialog() call means that it’s only run once. After we get the result from the dialog, we quit the main loop. That’ll cause the gtk_main() in your main MessageBox() method to return, and you’ll be able to access the result from there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 249k
  • Answers 249k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well.. ordinary people "program" their VCR, Tivo etc. So for… May 13, 2026 at 9:04 am
  • Editorial Team
    Editorial Team added an answer The DefaultValue attribute is only used to tell the Visual… May 13, 2026 at 9:04 am
  • Editorial Team
    Editorial Team added an answer My understanding is that Rails (3) will still essentially be… May 13, 2026 at 9:04 am

Related Questions

I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
I'm looking for some arguments to pitch to my boss and fellow developers. We're
Simply I have been trying to implement what BufferedStreamReader does in Java. I have
I've been trying to implement a bash script that reads from wordnet's online database
I have been trying to encrypt soap message and send to the server, so

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.