GetMessage函数

GetMessage函数从调用线程的消息队列中获取一个消息。该函数派送“发送消息”(非队列消息),直到取得一个可用的投递消息。

PeekMessage与GetMessage不同,PeekMessage不会等待有消息被投递才返回(言下之意就是,GetMessage函数会一直等待直到有消息被投递才会返回)。

函数原型:

BOOL GetMessage(        

 LPMSG lpMsg,

    HWND hWnd,

    UINT wMsgFilterMin,

    UINT wMsgFilterMax

);

参数说明:

lpMsg:指向一个MSG结构的指针,该结构中保存着从线程消息队列中取得的消息信息。

hWnd:取得消息的相关窗口句柄。该窗口必须属于正在调用的线程。NULL值有其特殊含义:GetMessage检索任何属于调用线程窗口的消息,并且通过PostThreadMessage函数将线程消息发送到调用线程。

wMsgFilterMin:指定被检索的最小消息值的整数。使用WM_KEYFIRST指定第一个键盘消息或WM_MOUSEFIRST指定第一个鼠标消息。

wMsgFilterMax:指定被检索的最大消息值的整数。使用WM_KEYLAST指定最后的键盘消息或WM_MOUSEFIRST指定最后的鼠标消息。

Windows XP:在wMsgFilterMin和wMsgFilterMax中指定WM_INPUT,则只获得WM_INPUT消息。

如果将wMsgFilterMin和wMsgFilterMax都指定为0,GetMessage函数会返回所有可用的消息(此时并没有设置消息的筛选范围)。

返回值:

如果函数检索到的消息不是WM_QUIT消息,则返回非0值。

如果函数检索到了WM_QUIT消息,则返回0值。

如果发生错误,返回值为-1。例如,参数hWnd是一个无效的窗口句柄或lpMsg是一个无效的指针。要获得更多的错误信息可以调用GetLastError函数。

警告:

因为函数的返回值可以为非0、0或-1,应该避免如下的代码:

while(GetMessage( lpMsg, hWnd, 0, 0)) ...

当出现GetMessage的返回值为-1时,将可能导致程序的致命错误。

使用如下的代码代替:

BOOL bRet;

 

while( (bRet = GetMessage( &msg, NULL, 0, 0 )) !=0)

{

    if (bRet == -1)

    {

        // handle the error and possibly exit

    }

    else

    {

        TranslateMessage(&msg);

        DispatchMessage(&msg);

    }

}

注意事项:

程序通常使用返回值来确定是否应该结束主消息循环并退出程序。

GetMessage函数检索由hWnd参数标识的关联窗体,或者由IsChild函数指定的它们子窗体的消息,并且消息范围在wMsgFilterMin和wMsgFilterMax参数指定值之间的消息。注意,应用只能用wMsgFilterMin和wMsgFilterMax参数的低字位,高字位是为系统保留的。

注意,不管在wMsgFilterMin和wMsgFilterMax指定的范围如何,GetMassage函数总是检索会WM_QUIT消息。

在函数调用期间,系统用SendMessage、SendMessageCallback,、SendMessageTimeout或者SendNotifyMessage函数发送待处理的、非队列的消息给属于当前线程的窗口。系统也可能处理内部事件。消息的处理顺序如下:

 Sentmessages(发送消息)

 Postedmessages(投递消息)

 输入(硬件)消息或者系统内部事件

 Sentmessages (again)(发送消息)

WM_PAINT消息

WM_TIMER消息

在投递消息之前检索输入消息,可以利用wMsgFilterMin和wMsgFilterMax参数做检索设置。

GetMessage不会从消息队列中移除WM_PAINT消息。该消息将一直存在于消息队列中直到被处理。


//原文如下:

The GetMessage function 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 GetMessage(      

    LPMSG lpMsg,
    HWND hWnd,
    UINT wMsgFilterMin,
    UINT wMsgFilterMax
);

Parameters

lpMsg
[out] Pointer to an MSG structure that receives message information from the thread's message queue.
hWnd
[in] Handle to the window whose messages are to be retrieved. The window must belong to the calling thread. The NULL value has a special meaning:
NULL
GetMessage retrieves messages for any window that belongs to the calling thread and thread messages posted to the calling thread using the PostThreadMessage function.
wMsgFilterMin
[in] Specifies the integer value of the lowest message value to be retrieved. Use WM_KEYFIRST to specify the first keyboard message or WM_MOUSEFIRST to specify the first mouse message.

Windows XP: Use WM_INPUT here and in wMsgFilterMax to specify only theWM_INPUT messages.

If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (that is, no range filtering is performed).

wMsgFilterMax
[in] Specifies 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.

Windows XP: Use WM_INPUT here and in wMsgFilterMin to specify only theWM_INPUT messages.

If wMsgFilterMin and wMsgFilterMax are both zero, GetMessage returns all available messages (that is, no range filtering is performed).

Return Value

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 ifhWnd is an invalid window handle orlpMsg is an invalid pointer. To get extended error information, call GetLastError.

Warning  

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:

Hide Example

BOOL bRet;

while( (bRet = GetMessage( &msg, NULL, 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 thehWnd parameter or any of its children, as specified by the IsChild function, and within the range of message values given by thewMsgFilterMin and wMsgFilterMax parameters. Note that an application can only use the low word in thewMsgFilterMin andwMsgFilterMax parameters; the high word is reserved for the system.

Note that GetMessage always retrievesWM_QUIT messages, no matter which values you specify forwMsgFilterMin andwMsgFilterMax.

During this call, the system delivers pending messages that were sent to windows owned by the calling thread using the SendMessage, SendMessageCallback, SendMessageTimeout, or SendNotifyMessage function. The system may also process internal events. 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 andwMsgFilterMax parameters.

GetMessage does not removeWM_PAINT messages from the queue. The messages remain in the queue until processed.

Windows XP: 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.

Windows 95/98/Me: GetMessageW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.


  • 7
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值