BOOL PeekMessage(lpmsg, hwnd, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg) | |||||
LPMSG lpmsg; | /* address of structure for message | */ | |||
HWND hwnd; | /* handle of the window | */ | |||
UINT uMsgFilterMin; | /* first message | */ | |||
UINT uMsgFilterMax; | /* last message | */ | |||
UINT fuRemoveMsg; | /* removal flags | */ |
The PeekMessage function checks a thread message queue for a message and places the message (if any) in the specified MSG structure.
lpmsg
Points to an MSG structure that contains message information from the Windows application queue. The MSG structure has the following form:
typedef struct tagMSG { /* msg */
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG;
hwnd
Identifies the window whose messages are to be examined.
uMsgFilterMin
Specifies the value of the first message in the range of messages to be examined.
uMsgFilterMax
Specifies the value of the last message in the range of messages to be examined.
fuRemoveMsg
Specifies whether the message should be removed from the queue. This parameter must be one of the following values:
Value | Meaning |
PM_NOREMOVE | ||
The message is not removed from the queue after processing by PeekMessage. | ||
PM_REMOVE | ||
The message is removed from the queue after processing by PeekMessage. |
The return value is TRUE if a message is available. Otherwise, it is FALSE.
Unlike the GetMessage function, the PeekMessage function does not wait for a message to be placed in the queue before returning.
PeekMessage retrieves only messages associated with the window specified by the hwnd parameter, or any of its children as specified by the IsChild function, and within the range of message values given by the uMsgFilterMin and uMsgFilterMax parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that belongs to the current thread making the call. (PeekMessage does not retrieve messages for windows that belong to other threads.) If hwnd is -1, PeekMessage returns only messages with an hwnd of NULL as posted by the PostAppMessage function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all available messages (no range filtering is performed).
The WM_KEYFIRST and WM_KEYLAST flags can be used as filter values to retrieve all key messages; the WM_MOUSEFIRST and WM_MOUSELAST flags can be used to retrieve all mouse messages.
PeekMessage does not remove WM_PAINT messages from the queue. The messages remain in the queue until processed.
GetMessage, IsChild, PostAppMessage, WaitMessage