January 27, 2011

Windows Message Queues Important Notes

About Messages and Message Queues
PeekMessage
Win32 Message Processing Primer
See also this post on this blog

PostMessage => Asynchronous, message goes into the message queue
SendMessage => Synchronous, message is sent to WinProc immediately and processed immediately.
Note: WM_PAINT, WM_TIMER, WM_QUIT handled differently when posted. They are only processed when there are no other messages in the queue. Multiple WM_PAINT messages for the same window are combined consolidating all invalid parts of the client area into a single area.
GetMessage() - Does not return until message matching the filter criteria is found. Removes message from queue
while (GetMessage (&msg, NULL, 0, 0))
{
  TranslateMessage (&msg) ;
  DispatchMessage (&msg) ;
}
PeekMessage() - Looks for message matching the filter criteria. Returns immediately. Whether the matching message is removed from the queue or not is determined by the last parameter of the method
do
{
  if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
  {
    TranslateMessage (&msg) ;
    DispatchMessage (&msg) ;
  }
} while (msg.message != WM_QUIT);
Neither GetMessage or PeekMessage will remove WM_PAINT messages unless the update area of the message is null!
 

No comments: