[Win32 API] GetMessage Function()

Retrieves a message from (only) the calling thread's message queue.

Syntax


BOOL WINAPI GetMessage(
  __out     LPMSG lpMsg,
  __in_opt  HWND hWnd,
  __in      UINT wMsgFilterMin,
  __in      UINT wMsgFilterMax
);


Parameters

  • lpMsg : A pointer to an MSG structure that recives message information from the thread's message queue.
  • hWind : A handle to the window whose message are to be retrieved. The Window must belong to the current thread.
    • If hWnd is NULL, GetMessage retrieves message for any window that belong to the current thread, and any messages on the current thread's message whose hwnd value is NULL. Therefore if hWnd is NULL, both window massages and thread messages are processed.
  • wMsgFilterMin : The integer value of the lowest message value to be retrieved.
    • ex) Use WM_KEYFIRST(0x0100) to specify the first keyboard message or WM_MOUSEFIRST(0x0200) to specify the first mouse message.
  • wMsgFilterMax : The integer value of the highest message value to be retrieved.
    • ex)Use WM_KEYLAST  to specify the last keyboard message.
    • If wMsgFilterMin and wMsgFilter are both zero, GetMassage return all available messages.
Return Value

If the function retreives the message WM_QUIT, return zero(false).
otherwise, return nonzero.(true)
This return value is using that escape infinite loop.
The possibility of a -1 return value means such code can lead to fatal application errors.

ex)
 BOOL bRet;
while( (bRet = GetMessage( &msg, hWnd, 0, 0 )) != 0)
{ 
    if (bRet == -1)
    {
        // handle the error and possibly exit
    }
    else
    {
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    }
}



댓글

이 블로그의 인기 게시물

[Win32 API] WINAPI - 함수호출규약

JAVA Frame Icon setting

JAVA Spinner