BOOL GetMessage(lpMsg,hWnd,wMsgFilterMin,wMsgFilterMax)
This function retrieves a message from the application queue and places the message
in the data structure pointed to by the lpMsg parameter. If no message is available, the
GetMessage function yields control to other applications until a message becomes available.
GetMessage retrieves only messages associated with the window specified by the hWnd parameter and within the range of message values given by the wMsgFilterMin and wMsgFilterMax parameters. If hWnd is NULL, GetMessage retrieves messages for any window that belongs to the application making the call. (The GetMessage function does not retrieve messages for windows that belong to other applications.) If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (no filtering is performed).
The constants WM_KEYFIRST and WM_KEYLAST can be used as filter values to retrieve all messages related to keyboard input; the constants WM_MOUSEFIRST and WM_MOUSELAST can be used to retrieve all mouse-related messages.
Parameter | Type/Description |
lpMsg | LPMSG Points to an MSG data structure that contains message information from the Windows application queue. | |
hWnd | HWND Identifies the window whose messages are to be examined. If hWnd is NULL, GetMessage retrieves messages for any window that belongs to the application making the call. | |
wMsgFilterMin | WORD Specifies the integer value of the lowest message value to be retrieved. | |
wMsgFilterMax | WORD Specifies the integer value of the highest message value to be retrieved. |
The return value specifies the outcome of the function. It is nonzero if a message other than WM_QUIT is retrieved. It is zero if the WM_QUIT message is retrieved.
The return value is usually used to decide whether to terminate the application's main loop and exit the program.
In addition to yielding control to other applications when no messages are available, the GetMessage and PeekMessage functions also yield control when WM_PAINT or WM_TIMER messages for other tasks are available.
The GetMessage, PeekMessage, and WaitMessage functions are the only ways to let other applications run. If your application does not call any of these functions for long periods of time, other applications cannot run.
When GetMessage, PeekMessage, and WaitMessage yield control to other applications, the stack and data segments of the application calling the function may move in memory to accommodate the changing memory requirements of other applications. If the application has stored long pointers to objects in the data or stack segment (that is, global or local variables), these pointers can become invalid after a call to GetMessage, PeekMessage, or WaitMessage. The lpMsg parameter of the called function remains valid in any case.