# SDL and MessageBox

This topic is 4903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This seemed so simple, but somehow it got me stumped. I'm trying to use the Win32 MessageBox function in my SDL application, after the window has been created. However, after calling MessageBox I can't select my window (which makes sense, since my dialog is modal), but the dialog does not show up, and my game continues. I guess it has something to do with the fact that SDL handles my events, but how to fix this? Code:
bool WarningYesNoBox( char *msg )
{
int ret = MessageBox( GetActiveWindow(), msg, "Warning", MB_YESNO | MB_ICONWARNING );
return( ret == IDYES );
}

bool GameView::pumpEvents()
{
SDL_Event event;
while( SDL_PollEvent(&event) != 0 )
{
switch( event.type )
{
case SDL_MOUSEBUTTONDOWN:
// [snip]... break;
case SDL_KEYDOWN:
// [snip]... break;
case SDL_QUIT:
return false;    // Stop the game..
default:
break;
}
}
return true;
}


##### Share on other sites
This may not be the problem but whenever I used a message box in my SDL stuff I passed NULL for the HWND parameter instead of calling GetActiveWindow(). This always worked fine for me and I didn't encounter any problems like you've described.

##### Share on other sites
Quote:
 Original post by SpudderThis may not be the problem but whenever I used a message box in my SDL stuff I passed NULL for the HWND parameter instead of calling GetActiveWindow(). This always worked fine for me and I didn't encounter any problems like you've described.

Same here, NULL works perfectly for me.

Passing in NULL means that the MessageBox isn't referring back to a parent window, passing in something other than NULL is only useful if you're working with an MDI app.

##### Share on other sites
I had NULL previously, but the only difference was that I could select my window as normal (since modality doesn't work without a parent window).

Alas.. Now I changed my error message to appear before my window is created, and there's absolutely no problem. Looks better anyway, so I'll stick with this.
Thanks for helping though!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 14
• 10
• 11
• 13
• ### Forum Statistics

• Total Topics
634096
• Total Posts
3015487
×