Technical Notes
Previous |
Home
DispatchMessage
Implementation Notes
DispatchMessage
takes one argument - a pointer to an object of type MSG
whose members hold complete information about the message. This includes a handle to the window for which the message is meant.
- This handle will always have a valid value except when the message has been posted through a call to
PostThreadMessage
. Conversely, whenever this handle has a valid value (i.e., it is not NULL
) we can assume that its for a window that already exists.
- If so we can safely derive that the function retrieves the pointer to the message handling function (from the
WNDCLASS
object registered with the system through a call to RegisterClass
) using this handle and invokes it.
- Regardless of the actual message that is generated, in order for it to be placed in the thread's message queue, a call to
PostMessage
has to be made (SendMessage
directly invokes the message processing function). The handle to the window for which the message is meant is supplied as a paramter to it. This message is ultimately retrieved from the queue through a call to GetMessage
and delegated to DispatchMessage
.
- This is understandable. But in the case that the message has been posted to the queue through a call to
PostThreadMessage
, the handle to the window in the MSG
structure will be NULL
. Therefore, DispatchMessage
cannot retrieve a pointer to the message processing function. This begs a rather obvious question - to whom or what pray will DispatchMessage
dispatch the message? The answer is, the message will not be dispatched anywhere! It will simply diappear into oblivion!
Previous |
Home