Jump to content
  • Advertisement
Sign in to follow this  
taz0010

Windows API modal popups

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just ran into a bug caused by displaying modal dialog boxes for debug purposes during the execution of some code. The dialog box seems to suspend the current thread it runs on, but certain messages in the message loop are still passed through, so it was possible to use the mouse to begin a new operation while the old operation was still in progress.

I'd like to know exactly how modal popups work in the Windows API so I don't run into these problems again.

While a modal popup is showing, what's actually happening with the message loop that called the winProc which resulted in the dialog box appearing in the first place? Does Windows spawn a worker thread and somehow activate the original message loop again, or are future user input events redirected to some other message loop behind the scenes? If I have code inside the loop between GetMessage and DispatchMessage, will this code execute while a modal dialog box is blocking the original thread? If not, that would make it unsafe to put any sort of custom code inside your message loop if you plan to use modal popups at all.

Share this post


Link to post
Share on other sites
Advertisement
No, not at all - a modal message box implements its own message pump internally and provided we are just talking about the window that created the message box (the HWND you pass as the first param to MessageBox), it should not be possible to interact with the window or for the application message loop to receive messages as far as I know.

You do need to manually disable any other modeless windows that you may have open - tool windows etc.

Could you post:


  • Your main message loop
  • The code you call the message box with

Share this post


Link to post
Share on other sites

No, not at all - a modal message box implements its own message pump internally and provided we are just talking about the window that created the message box (the HWND you pass as the first param to MessageBox), it should not be possible to interact with the window or for the application message loop to receive messages as far as I know.

You do need to manually disable any other modeless windows that you may have open - tool windows etc.

Could you post:

  • Your main message loop
  • The code you call the message box with


I assume it was still possible to interact with the window because I passed 0 into the MessageBox function instead of the HWND of my main window. The message box was for debugging purposes and that part of the code didn't have access to the window handle, or any part of the GUI at all. The DirectX math header includes windows.h, which pollutes the hell out of the global namespace which was why I was able to call MessageBox from there in the first place. heh.


I assume passing the HWND of my application's main window to MessageBox will freeze it and all it's child windows? If I passed in the HWND of a child window, it would only freeze that window's children but not the window's parent, correct?

Share this post


Link to post
Share on other sites
Good, that's solved then. You must pass the HWND of the owner window - NULL will create a parentless dialog which, while technically modal, obviously isn't in the way we want.

Re the other question, last time I tried a main application, child windows (floating tool windows) and dialog boxes launched by the main window, I had to manually disable and re-enable the child windows before and after the dialog box calls, with EnableWindow().

I'm assuming the same is true for message boxes but it is, I guess, possible that they work differently to dialog boxes and disable the whole application. I can't help here - try it and if the child windows are still active, you'll need to use EnableWindow() on them to manually control this.

Share this post


Link to post
Share on other sites
You're welcome.

Man, these end-of-thread pleasantries use a lot of vertical space now. Probably better to be rude and not say thanks, or invest in companies that make mouse scroll wheels. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!