Den 08. april 2011 13:15, skrev Joerg-Cyril.Hoehle@t-systems.com:
DispatchMessage is not always needed. Unfortunately, I don't grok yet when DispatchMessage is required.
http://blogs.msdn.com/b/oldnewthing/archive/2004/06/08/150929.aspx "Everybody who has messed with window messaging knows that GetMessage and PeekMessage retrieve queued messages, which are dispatched to windows via DispatchMessage."
None the clearer. If I just retrieved them (they were obviously "dispatched" to my queue), why must I dispatch again?
No, they were *not* dispatched to your queue, they were queued (posted). DispatchMessage calls the appropriate window procedure, it is not used to queue messages.
Sending and queuing is *not* the same. The rule is basically:
- If the message was queued with Post*Message, then GetMessage/PeekMessage returns it and you should pass it to DispatchMessage. - If the message was sent with Send*Message, then GetMessage/PeekMessage handles (dispatches) it, does not return it, and thus DispatchMessage would never even see it.
Consider sent messages synchronous, and posted/queued messages as asynchronous. Windows may reorder queued (asynchronous) messages by message priority class, so that e.g. GetMessage may return a WM_PAINT only after all other (higher-priority) messages have been returned and dispatched.
I.e. what's the kind of work that the function calling GetMessage Should/can do vs. the work to be done by whatever function DispatchMessage eventually calls?
The function calling GetMessage isn't supposed to do anything beyond calling DispatchMessage.