An application can use the PeekMessage function when it checks the queues for messages but does not want to pull the message from the queue. The function returns a nonzero value if a message is in the queue, and lets the application retrieve the message and process it without going through the application's main 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 terminate 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 queue.