GetMessage function (Windows)
来源:互联网 发布:新浪云 端口 编辑:程序博客网 时间:2024/05/22 11:38
原文地址::http://msdn.microsoft.com/ZH-CN/library/windows/desktop/ms644936(v=vs.85).aspx
Retrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a posted message is available for retrieval.
Unlike GetMessage, the PeekMessage function does not wait for a message to be posted before returning.
Syntax
BOOL WINAPI GetMessage( _Out_ LPMSG lpMsg, _In_opt_ HWND hWnd, _In_ UINT wMsgFilterMin, _In_ UINT wMsgFilterMax);
Parameters
- lpMsg [out]
Type: LPMSG
A pointer to an MSG structure that receives message information from the thread's message queue.
- hWnd [in, optional]
Type: HWND
A handle to the window whose messages are to be retrieved. The window must belong to the current thread.
If hWnd is NULL, GetMessage retrieves messages for any window that belongs to the current thread, and any messages on the current thread's message queue whose hwnd value is NULL(see the MSG structure). Therefore if hWnd is NULL, both window messages and thread messages are processed.
If hWnd is -1, GetMessage retrieves only messages on the current thread's message queue whose hwnd value is NULL, that is, thread messages as posted by PostMessage (when the hWndparameter is NULL) or PostThreadMessage.
- wMsgFilterMin [in]
Type: UINT
The integer value of the lowest message value to be retrieved. Use WM_KEYFIRST (0x0100) to specify the first keyboard message or WM_MOUSEFIRST (0x0200) to specify the first mouse message.
Use WM_INPUT here and in wMsgFilterMax to specify only the WM_INPUT messages.
If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (that is, no range filtering is performed).
- wMsgFilterMax [in]
Type: UINT
The integer value of the highest message value to be retrieved. Use WM_KEYLAST to specify the last keyboard message or WM_MOUSELAST to specify the last mouse message.
Use WM_INPUT here and in wMsgFilterMin to specify only the WM_INPUT messages.
If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (that is, no range filtering is performed).
Return value
Type:
Type: BOOL
If the function retrieves a message other than WM_QUIT, the return value is nonzero.
If the function retrieves the WM_QUIT message, the return value is zero.
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, call GetLastError.
Because the return value can be nonzero, zero, or -1, avoid code like this:
while (GetMessage( lpMsg, hWnd, 0, 0)) ...
The possibility of a -1 return value means that such code can lead to fatal application errors. Instead, use code like this:
BOOL bRet;while( (bRet = GetMessage( &msg, hWnd, 0, 0 )) != 0){ if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); }}
Remarks
An application typically uses the return value to determine whether to end the main message loop and exit the program.
The GetMessage function retrieves messages associated with the window identified by the hWndparameter 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. Note that an application can only use the low word in the wMsgFilterMin and wMsgFilterMax parameters; the high word is reserved for the system.
Note that GetMessage always retrieves WM_QUIT messages, no matter which values you specify forwMsgFilterMin and wMsgFilterMax.
During this call, the system delivers pending, nonqueued messages, that is, messages sent to windows owned by the calling thread using the SendMessage, SendMessageCallback, SendMessageTimeout, orSendNotifyMessage function. Then the first queued message that matches the specified filter is retrieved. The system may also process internal events. If no filter is specified, messages are processed in the following order:
- Sent messages
- Posted messages
- Input (hardware) messages and system internal events
- Sent messages (again)
- WM_PAINT messages
- WM_TIMER messages
To retrieve input messages before posted messages, use the wMsgFilterMin and wMsgFilterMaxparameters.
GetMessage does not remove WM_PAINT messages from the queue. The messages remain in the queue until processed.
If a top-level window stops responding to messages for more than several seconds, the system considers the window to be not responding and replaces it with a ghost window that has the same z-order, location, size, and visual attributes. This allows the user to move it, resize it, or even close the application. However, these are the only actions available because the application is actually not responding. When in the debugger mode, the system does not generate a ghost window.
Examples
For an example, see Creating a Message Loop.
Requirements
Minimum supported client
Minimum supported server
Header
- Winuser.h (include Windows.h)
Library
- User32.lib
DLL
- User32.dll
Unicode and ANSI names
See also
- Reference
- IsChild
- MSG
- PeekMessage
- PostMessage
- PostThreadMessage
- WaitMessage
- Conceptual
- Messages and Message Queues
Send comments about this topic to Microsoft
Build date: 10/16/2012
//=================================
备注::
1>看来很多WINDOWS API函数都别有洞天啊!不看不知道,一细看吓一跳,原来自己对WINDOWS下基本的API了解的也是这样的肤浅,
实在是惭愧啊!
2>对东西都把握不准,谈何把它用好用准呢?对WINDOWS下基本的API都只知道个模糊的概念,看来我的WINDOWS编程还没有入门啊!
3>
The possibility of a -1 return value means that such code can lead to fatal application errors. Instead, use code like this:
BOOL bRet;while( (bRet = GetMessage( &msg, hWnd, 0, 0 )) != 0){ if (bRet == -1) { // handle the error and possibly exit } else { TranslateMessage(&msg); DispatchMessage(&msg); }}
- GetMessage function (Windows)
- GetMessage Function使用注意的地方
- Windows 消息GetMessage伪代码
- GetMessage
- GetMessage()
- GetMessage
- GetMessage
- GetMessage
- 深入GetMessage,PeekMessage以及Windows消息机制
- windows编程之PeekMessage与Getmessage
- 深入GetMessage,PeekMessage以及Windows消息机制
- Windows API一日一练(11)GetMessage函数
- GetMessage与PeekMessage(16位windows程序)
- Windows消息响应机制之四:PostQuitMessage和GetMessage函数
- Windows消息响应机制之四:PostQuitMessage和GetMessage函数 .
- Windows 线程消息队列和GetMessage实现内幕
- Windows消息响应机制之四:PostQuitMessage和GetMessage函数
- Windows API - Timer Function
- volatile关键字
- C/C++常用宏定义
- apache安装配置总结
- php gerr 统一的错误处理 v0
- Linux文件权限与属性 的简单说明
- GetMessage function (Windows)
- [Usaco2008 Oct]笨重的石子 DP
- 2012.11.29
- matifest.mf文件内容详解
- Parcelable
- php 数据库访问类(模型 Model) v1.1
- MANIFEST.MF的用途
- [Usaco2008 Nov]lites 开关灯 线段树 区间异或及求和操作
- Java冒泡排序法