To answer your question, each message in the queue stores at least
- handle to the window the message is directed to
- message code, wParam and lParam, as you rightly noted,
- The post time of the message you retrieve using
GetMessageTime() , - for user interface messages, the cursor position when the message was published (see
GetMessagePos() ).
Please note that not all messages are actually queued. Messages that are sent with SendMessage() window from the stream to which the window belongs are never saved; instead, the message function of the recipient window is called directly. Messages sent from other threads are saved until they are processed, and the sending thread is blocked until a message is received, either by exiting a window function or explicitly calling ReplyMessage() . The InSendMessage() API function helps you determine if the Windows function is processing a message sent from another thread.
Messages that you or the system publish are queued, with some exceptions.
WM_TIMER messages are never saved; instead, GetMessage() creates a timer message if there are no other messages in the queue and the timer has matured. This means that, firstly, timer messages have the lowest priority to delete from the queue, and secondly, several messages from the timer with a short period will never be overflowed by the queue, even if GetMessage() not called for some time. As a result, one WM_TIMER message is sent for this timer, even if the timer has passed several times since the last WM_TIMER message was processed from this timer.
Similarly, WM_QUIT is also not saved, but only marked. GetMessage() pretends to have received WM_QUIT after the queue has been exhausted, and this is the last message it receives.
Another example is the WM_PAINT message (@ cody-gray hint to remind you of this). This message is also mimicked when any part of the window is marked as dirty and needs to be repainted. This is also a low-priority message that was created so that several invalid areas in the window are repainted at the same time when the queue becomes empty, to reduce the responsiveness of the GUI and reduce flicker. You can call an immediate redraw by calling UpdateWindow() . This function acts like SendMessage() , in the sense that it does not return until the open part of the window is redrawn. This function does not send WM_PAINT to the window if the invalid area of this window is empty, as an obvious optimization.
There may be other exceptions and internal optimizations.
Messages sent using PostMessage() fall into the thread queue to which the window to which the message is sent belongs.
What form of messages are stored inside, we do not know, and we do not care. The Windows API abstracts this completely. The MSG structure is populated in the memory you pass to GetMessage() or PeekMessage() . You do not need to know or worry about the details of the internal implementation beyond those described in the Windows SDK manuals.
¹ I do not know exactly how WM_PAINT and WM_TIMER take precedence over each other. I assume WM_PAINT has a lower priority, but I could be wrong.
source share