1.1.3 Examining Messages

An application can use the PeekMessage function to examine its message queue for specific messages without removing them from the queue. The function returns a nonzero value if a message exists in the queue and lets the application retrieve the message and process it without going through the application's main message loop.

Typically, an application uses PeekMessage to check periodically for messages when the application is carrying out a lengthy operation, such as processing input and output. For example, this function can be used to check for messages that end the operation. PeekMessage also gives the application a chance to yield control if no messages are present, because PeekMessage can yield if no messages are in the message queue.