Reputation: 147018
I've got a relatively simple Window class. I've created a window, associated my this
, etc etc. Now later, I've thrown an exception to indicate a problem. When I call MessageBox
to pop up the error, the program crashes, because it's attempting to call my Window Proc. Now, I mean, admittedly, I failed SRP here and just writing a brief self-owning HWND class will solve this problem, as the window wasn't cleaned up properly. However, I'm really mystified as to why it's trying to process Window messages in my MessageBox
call- the owner parameter is nullptr
. Any suggestions?
Edit: If I call DestroyWindow
appropriately, then now the message box just doesn't show up, although the app doesn't crash. It only works if I manually remove this
from the window, so that if the proc were called it would forward to DefWindowProc
, and then DestroyWindow
. I mean, I thought that if you called MessageBox
without an owner, then it would just work, regardless of what you had done to other windows in the system.
Upvotes: 3
Views: 474
Reputation: 613461
What is happening here is that there are still messages for the dud window in the queue when you show the message box. The message box runs a modal window message pump and dispatches the troublesome messages. Remember that all windows created from the same thread share a single message queue.
I have no idea how to fix your problem but that's what's going on.
By the way, passing a null owner isn't a great idea as it will result in your message box not being minimised when your main app is minimised, for example.
Upvotes: 4