If system or queue hooks are installed, they are called before this function returns.

rc is generally used to determine when to terminate the application's main loop and exit the program.

hwndFilter constrains the returned message to be for a specific window or its children. When hwndFilter is null, the returned message can be for any window. The message identity is restricted to the range of message identities specified by ulFirst and ulLast inclusive. When ulFirst and ulLast are both zero, any message satisfies the range constraint. When ulFirst is greater than ulLast, messages except those whose identities lie between ulFirst and ulLast are eligible to be returned. Messages that do not conform to the filtering criteria remain in the queue.

When hwndFilter is null, and ulFirst and ulLast are both zero, all messages are returned in the order that they were posted to the queue.

By using filtering, messages can be processed in an order that is different from the one in the queue. Filtering is used in situations where applications receive messages of a particular type, rather than having to deal with other types of message at an inconvenient point in the logic of the application. For example, when a "mouse down" message is received, filtering can be used to wait for the "mouse up" message without having to be concerned with receiving other messages.

These constants can also be used when filtering messages: