检查消息队列(Examining a Message Queue)
来源:互联网 发布:炒银软件 编辑:程序博客网 时间:2024/05/18 03:16
检查消息队列(Examining a Message Queue)
一个应用程序需要检查来自于线程消息循环之外的一个线程消息队列的内容。例如,如果应用程序的窗口过程正在执行一个很长的绘画操作,但是你可能想要用户可以中断这个操作。除非你的应用程序可以在鼠标和键盘消息输入时定期检查消息队列,否则它将不会响应用户输入直到这个操作结束。这个情况发生的原因是在线程消息队列中,DispatchMessage函数直到窗口过程处理消息结束时才能返回。
在一个长操作过程中,你可以利用PeekMessage函数来检查一个消息队列。PeekMessage函数类似于GetMessage函数,这两个函数都可以通过检查消息队列来寻找匹配过滤规则的消息,并把消息复制到MSG结构中。这两个函数最主要的区别是GetMessage函数不会立即返回,直到一个匹配过滤规则的消息被放到队列中。然而PeekMessage函数会立即返回,无论消息是否在队列中。
下面的例如展示了如何利用PeekMessage函数在长操作时,通过消息队列来检查鼠标点击和键盘输入消息。
HWND hwnd;
BOOL fDone;
MSG msg;
// Begin the operation and continue until it is complete
// or until the user clicks the mouse or presses a key.
fDone = FALSE;
while (!fDone)
{
fDone = DoLengthyOperation(); // application-defined function
// Remove any messages that may be in the queue. If the
// queue contains any mouse or keyboard
// messages, end the operation.
while (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE))
{
switch(msg.message)
{
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_KEYDOWN:
//
// Perform any required cleanup.
//
fDone = TRUE;
}
}
}
其他的函数包括GetQueueStatus和GetInputState函数,也允许你检查线程消息队列。GetQueueStatus返回一个标志符数组,这些标识符表明了队列中的消息类型。利用这个函数是最快的检查消息队列是否有消息的方式。如果队列中含有鼠标或键盘消息,GetInputState函数会返回TRUE。这两个函数都可以用来确定消息队列中是否含有需要被处理的消息。
一个应用程序需要检查来自于线程消息循环之外的一个线程消息队列的内容。例如,如果应用程序的窗口过程正在执行一个很长的绘画操作,但是你可能想要用户可以中断这个操作。除非你的应用程序可以在鼠标和键盘消息输入时定期检查消息队列,否则它将不会响应用户输入直到这个操作结束。这个情况发生的原因是在线程消息队列中,DispatchMessage函数直到窗口过程处理消息结束时才能返回。
在一个长操作过程中,你可以利用PeekMessage函数来检查一个消息队列。PeekMessage函数类似于GetMessage函数,这两个函数都可以通过检查消息队列来寻找匹配过滤规则的消息,并把消息复制到MSG结构中。这两个函数最主要的区别是GetMessage函数不会立即返回,直到一个匹配过滤规则的消息被放到队列中。然而PeekMessage函数会立即返回,无论消息是否在队列中。
下面的例如展示了如何利用PeekMessage函数在长操作时,通过消息队列来检查鼠标点击和键盘输入消息。
HWND hwnd;
BOOL fDone;
MSG msg;
// Begin the operation and continue until it is complete
// or until the user clicks the mouse or presses a key.
fDone = FALSE;
while (!fDone)
{
fDone = DoLengthyOperation(); // application-defined function
// Remove any messages that may be in the queue. If the
// queue contains any mouse or keyboard
// messages, end the operation.
while (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE))
{
switch(msg.message)
{
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_KEYDOWN:
//
// Perform any required cleanup.
//
fDone = TRUE;
}
}
}
其他的函数包括GetQueueStatus和GetInputState函数,也允许你检查线程消息队列。GetQueueStatus返回一个标志符数组,这些标识符表明了队列中的消息类型。利用这个函数是最快的检查消息队列是否有消息的方式。如果队列中含有鼠标或键盘消息,GetInputState函数会返回TRUE。这两个函数都可以用来确定消息队列中是否含有需要被处理的消息。
- 检查消息队列(Examining a Message Queue)
- Examining a Message Queue
- 消息队列 (Message Queue)
- 消息队列 ( Message Queue )
- 消息队列(Message Queue)
- 消息队列(Message Queue)
- 消息队列(Message Queue)
- 消息队列 posix message queue
- 消息队列(Message Queue)
- 消息队列(Message Queue)
- 消息队列(message queue)
- 6.3 消息队列 message queue
- ipc 消息队列message queue
- Posix message queue 消息队列
- IPC 消息队列(message queue)
- Message queue消息队列,MQ
- MSMQ(MicroSoft Message Queue,微软消息队列)
- 消息队列(Message Queue)编程
- 尚学堂OA碰到 不知道怎么注解如何Map和List集合 希望高手解答
- Linux/Unix版对本版块的精华帖分类汇总
- Windows内存管理
- java.lang.NoClassDefFoundError: org.apache.commons.logging.LogFactory.class
- 一个有趣的抛硬币问题
- 检查消息队列(Examining a Message Queue)
- inline function
- 美国《独立宣言》全文
- NSValue包装对象指针,CGRect结构体等
- http://www.pin5i.com/showtopic-24070-3.html
- SO_KEEPALIVE套接口选项(转载)
- fstream读取文件
- POJ 1799 几何题目 题意简单明了
- There is no Action mapped for namespace [/] and action name [hello] associated with context path [/