An application can choose specific messages to retrieve from the message queue (ignoring other messages) by specifying a message filter with the GetMessage or PeekMessage function. The message filter is a range of message identifiers (specified by a first and last identifier), a window handle, or both. The GetMessage and PeekMessage functions use the message filter to select the messages to retrieve from the queue. Message filtering is useful if an application needs to search the message queue for messages that arrived in the queue later than other messages.
Any application that filters messages must ensure that a message satisfying the message filter can be posted. For example, filtering for a WM_CHAR message in a window that does not receive keyboard input prevents the GetMessage function from returning. This will effectively hang the application.
To filter for keyboard, mouse, and DDE messages, an application can use the constants WM_KEYFIRST and WM_KEYLAST, WM_MOUSEFIRST and WM_MOUSELAST, and WM_DDE_FIRST and WM_DDE_LAST.