PeekMessage

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

This function checks a thread message queue for a message and places the message (if any) in the specified structure.

Syntax

BOOL PeekMessage(
  LPMSG lpMsg, 
  HWND hWnd, 
  UINT wMsgFilterMin, 
  UINT wMsgFilterMax, 
  UINT wRemoveMsg 
); 

Parameters

  • lpMsg
    [out] Pointer to an MSG structure that receives message information.
  • hWnd
    [in] Handle to the window whose messages are to be examined.
  • wMsgFilterMin
    [in] Specifies the value of the first message in the range of messages to be examined.
  • wMsgFilterMax
    [in] Specifies the value of the last message in the range of messages to be examined.
  • wRemoveMsg
    [in] Specifies how messages are handled. This parameter can be one of the following values.

    Value Description

    PM_NOREMOVE

    Messages are not removed from the queue after processing by PeekMessage.

    PM_REMOVE

    Messages are removed from the queue after processing by PeekMessage. An exception is WM_PAINT messages, which are not removed from the queue.

    You can optionally combine the value PM_NOYIELD with either PM_NOREMOVE or PM_REMOVE. This flag prevents the system from releasing any thread that is waiting for the caller to go idle.

Return Value

Nonzero indicates success. Zero indicates failure.

Remarks

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 identified 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 wMsgFilterMin and wMsgFilterMax 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 only returns messages with a hWnd value of NULL, as posted by the PostThreadMessage function. If wMsgFilterMin and wMsgFilterMax are both zero, PeekMessage returns all available messages (that is, no range filtering is performed).

The WM_KEYFIRST and WM_KEYLAST constants can be used as filter values to retrieve all keyboard messages; the WM_MOUSEFIRST and WM_MOUSELAST constants can be used to retrieve all mouse messages.

The PeekMessage function does not remove WM_PAINT messages from the queue. WM_PAINT messages remain in the queue until they are processed.

Calling PeekMessage before the top level window of an application is created will result in the window being created at the back of the z-order. You will need to explicitly call SetForegroundWindowto show the window when it is created after a call to PeekMessage. If the application already has a window in the foreground, then the new window will be created in the foreground.

Requirements

Header winuser.h
Library coredll.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also

Reference

Message Queue Functions
GetMessage
IsChild
PostThreadMessage
MSG