GetMessage(Msg, 0, 0, 0) ( 积分: 50 )

  • 主题发起人 主题发起人 Delphi假小子
  • 开始时间 开始时间
D

Delphi假小子

Unregistered / Unconfirmed
GUEST, unregistred user!
GetMessage(Msg, 0, 0, 0)<br>是什么意思? 第二个参数为0又是什么意思?
 
GetMessage(Msg, 0, 0, 0)<br>是什么意思? 第二个参数为0又是什么意思?
 
GetMessage<br>The GetMessage function retrieves a message from the calling thread's message queue and places it in the specified structure. This function can retrieve both messages associated with a specified window and thread messages posted via the PostThreadMessage function. The function retrieves messages that lie within a specified range of message values. GetMessage does not retrieve messages for windows that belong to other threads or applications. <br><br>BOOL GetMessage(<br> &nbsp;LPMSG lpMsg, &nbsp; &nbsp; &nbsp; &nbsp; // address of structure with message<br> &nbsp;HWND hWnd, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // handle of window<br> &nbsp;UINT wMsgFilterMin, &nbsp;// first message<br> &nbsp;UINT wMsgFilterMax &nbsp; // last message<br>);<br> <br>Parameters<br>lpMsg <br>Pointer to an MSG structure that receives message information from the thread's message queue. <br>hWnd <br>Handle to the window whose messages are to be retrieved. One value has a special meaning: Value Meaning <br>NULL GetMessage retrieves messages for any window that belongs to the calling thread and thread messages posted to the calling thread via PostThreadMessage. <br><br><br>wMsgFilterMin <br>Specifies the integer value of the lowest message value to be retrieved. <br>wMsgFilterMax <br>Specifies the integer value of the highest message value to be retrieved. <br>Return Values<br>If the function retrieves a message other than WM_QUIT, the return value is nonzero.<br><br>If the function retrieves the WM_QUIT message, the return value is zero. <br><br>If there is an error, the return value is -1. For example, the function fails if hWnd is an invalid window handle or lpMsg is an invalid pointer. To get extended error information, callGetLastError.<br><br>Remarks<br>An application typically uses the return value to determine whether to end the main message loop and exit the program. <br><br>The GetMessage function only retrieves 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, GetMessage retrieves messages for any window that belongs to the calling thread and thread messages posted to the calling thread via PostThreadMessage. GetMessage does not retrieve messages for windows that belong to other threads nor for threads other than the calling thread, even if hWnd is not NULL. Thread messages, posted by the PostThreadMessage function, have a message hWnd value of NULL. If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (that is, no range filtering is performed). <br><br>The WM_KEYFIRST and WM_KEYLAST constants can be used as filter values to retrieve all messages related to keyboard input; the WM_MOUSEFIRST and WM_MOUSELAST constants can be used to retrieve all mouse messages. If the wMsgFilterMin and wMsgFilterMax parameters are both zero, the GetMessage function returns all available messages (that is, without performing any filtering). <br><br>GetMessage does not remove WM_PAINT messages from the queue. The messages remain in the queue until processed. <br><br>Note that the function return value can be nonzero, zero, or -1. Thus, you should avoid code like this:<br><br>while (GetMessage( lpMsg, hWnd, 0, 0)) ... <br> <br>The possibility of a -1 return value means that such code can lead to fatal application errors. <br><br>QuickInfo<br> &nbsp;Windows NT: Requires version 3.1 or later.<br> &nbsp;Windows: Requires Windows 95 or later.<br> &nbsp;Windows CE: Requires version 1.0 or later.<br> &nbsp;Header: Declared in winuser.h.<br> &nbsp;Import Library: Use user32.lib.<br> &nbsp;Unicode: Implemented as Unicode and ANSI versions on Windows NT.<br><br>See Also<br>Messages and Message Queues Overview, Message and Message Queue Functions, IsChild, MSG, PeekMessage, PostMessage, PostThreadMessage, WaitMessage <br><br> <br>
 
此函数的返回值是boolean类型的,通常用返回值来确定是否终止主消息循环并退出程序,第二个参数为零,可能(我也不太清楚)表示GetMessage为任何属于调用线程的窗口检索消息,第三、四参数都是零表示返回所有可得的消息。
 
GetMessage是取出当前线程消息队列中的消息,通常用来作消息循环.<br>所谓消息循环,即不断得取出消息然后把消息分发到处理过程处理之.<br>所谓分发本质上说就是调用处理过程回调函数.典型的消息循环如下:<br><br> // 如果未取到消息,则挂起该线程,直至有消息进入消息队列<br> &nbsp;while GetMessage(Msg, 0, 0, 0) do<br> &nbsp;begin<br> &nbsp; &nbsp;TranslateMessage(Msg); // 将按键类消息转换为字符消息<br> &nbsp; &nbsp;DispatchMessage(Msg); &nbsp;// 将消息分发到处理过程(调用)<br> &nbsp;end; &nbsp;
 
第一个参数指定 取出的消息放到那个结构本来<br>第二个参数指定 取那个窗口的消息(0代表所有)<br>第三个参数和第四个参数指定取某个范围的消息
 
后退
顶部