-
June 24th, 2008, 05:49 AM
#1
Modal dialog and messages
'lo everybody.
I'm working on this very complex software, and there is this small bug I don't know how to get rid of. Perhaps some of you might be able to help.
Here is what happens : a "splash" window is created at startup while the software performs various initializations. This window is a modal dialog, called with DoModal(). When the initialization is complete, another thread posts a custom WM_USER message to the splash window, which then closes itself with EndDialog(IDOK) and returns from the DoModal() call.
This works fine, except if the splash window is being moved when the message is sent. Under these circumstances, it seems the message is either ignored or lost.
So, is this "normal" behavior? I'm guessing the WM_MOVEWINDOW or whatever message takes priority over the custom WM_USER message. More importantly, how can I correct this? (I'm thinking of making the splash window not moveable, but this obviously is a workaround, not an actual fix.)
Thanks for your help!
-
June 24th, 2008, 05:53 AM
#2
Re: Modal dialog and messages
Did you try a SendMessage instead of a PostMessage? This API should wait untill the message was processed ...
You should read the documentation of SendMessage and SendMessageTimeout...
regards
HoM
-
June 24th, 2008, 06:36 AM
#3
Re: Modal dialog and messages
Originally Posted by wlof
So, is this "normal" behavior? I'm guessing the WM_MOVEWINDOW or whatever message takes priority over the custom WM_USER message. More importantly, how can I correct this? (I'm thinking of making the splash window not moveable, but this obviously is a workaround, not an actual fix.)
Thanks for your help!
1. There is no WM_MOVEWINDOW at all.
2. I never heard something about any "priority" over user defined messages. However, messages that have been posted are placed in the message queue and not processed until window procedure ends processing some other ("sent") messages.
3. You should NOT use WM_USER range for your custom user messages since this range is already used by Windows and MFC.
You should use WM_APP range instead.
Victor Nijegorodov
-
June 24th, 2008, 07:50 AM
#4
Re: Modal dialog and messages
Thanks to you both.
HoM: Thanks, but the problem isn't whether the call is blocking or not. The PostMessage() is actually the last step of an initialization thread, which terminates itself right after that, so it doesn't really matter whether Post or SendMessage() is used.
VictorN:
1. Yep, I made it up. I don't know if there is an actual "high level" message to tell a window it is being moved, or if it's just the "low level" WM_MOVEMOUSE|WM_LBUTTONDOWN messages or something else entirely.
2. Is there any way to manipulate or bypass the message queue? If I want the window to close itself, I think I can safely tell it to drop all other unprocessed messages.
3. Thanks for the tip. I switched the messages to the WM_APP range, but it doesn't seem to change anything.
-
June 24th, 2008, 08:01 AM
#5
Re: Modal dialog and messages
HoM: Thanks, but the problem isn't whether the call is blocking or not. The PostMessage() is actually the last step of an initialization thread, which terminates itself right after that, so it doesn't really matter whether Post or SendMessage() is used.
Did you give it a try?
regards
HoM
-
June 24th, 2008, 08:03 AM
#6
Re: Modal dialog and messages
Originally Posted by HoM
Did you give it a try?
Yep. From what I can tell, it changes nothing.
-
June 24th, 2008, 08:07 AM
#7
Re: Modal dialog and messages
Seems the issue is not unknown ...
MS Support
... kind of. Hard to understand this article :-(
regards
HoM
-
June 24th, 2008, 08:25 AM
#8
Re: Modal dialog and messages
Well, I managed to solve my bug in a simpler way. The exact problem was that the main window can receive messages from other threads that triggers graphical changes, but the graphical elements might not exist yet because the main window's OnInitDialog() method is still stopped in dlgSplash.DoModal().
It now checks whether an element exists before attempting to update it.
I'm still interested in whether it's possible to manipulate the message queues or not, but that's just curiousity at this point.
-
June 24th, 2008, 01:24 PM
#9
Re: Modal dialog and messages
I think the simplest solution is to just call DestroyWindow. It cannot fail, no matter what UI you have or don't have. Just make sure, before calling it, that the window exists. And also make sure that no other code sequence will attempt to access it anymore.
There is no WM_MOVEWINDOW message but there is WM_MOVE and WM_MOVING.
In my opinion there are two categories of programmers who touch the message queue:
1. Highly skilled programmers writing advanced applications to deal specifically with the message queue.
2. Those who don't know enough programming to achieve their goals using normal programming techniques.
(I excluded the cases when it's clearly stated in the MSDN that the message queue must be modified.)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|