windows中进队消息和不进队消息的区别?

quwei197874 2011-08-25 11:45:51
如题,请各位解释一下
...全文
162 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
moheng1 2011-08-25
  • 打赏
  • 举报
回复
4楼说的对。。。
gold_water 2011-08-25
  • 打赏
  • 举报
回复
消息分为队列消息(进入线程的消息队列)和非队列消息(不进入线程的消息队列)。对于队列消息,最常见的是鼠标和键盘触发的消息,例如WM_MOUSERMOVE,WM_CHAR等消息;还有例如:WM_PAINT、WM_TIMER和WM_QUIT。当鼠标、键盘事件被触发后,相应的鼠标或键盘驱动程序就会把这些事件转换成相应的消息,然后输送到系统消息队列,由Windows系统负责把消息加入到相应线程的消息队列中,于是就有了消息循环(从消息队列中读取并派送消息)。还有一种是非队列消息,他绕过系统队列和消息队列,直接将消息发送到窗口过程。例如,当用户激活一个窗口系统发送WM_ACTIVATE, WM_SETFOCUS, and WM_SETCURSOR。创建窗口时发送WM_CREATE消息。在后面你将看到,MS这么设计是很有道理的,以及他的整套实现机制
ndy_w 2011-08-25
  • 打赏
  • 举报
回复
Windows uses two methods to route messages to a window procedure: (1) posting messages to a first-in, first-out queue called a message queue, which is a system-defined memory object that temporarily stores messages; and (2) sending messages directly to a window procedure. Messages posted to a message queue are called queued messages. They are primarily the result of user input via the mouse or keyboard, such as WM_MOUSEMOVE, WM_LBUTTONDOWN, WM_KEYDOWN, and WM_CHAR messages. Other queued messages include the timer, paint, and quit messages: WM_TIMER, WM_PAINT, and WM_QUIT. Most other messages are sent directly to a window procedure and are called, surprisingly enough, nonqueued messages.

Queued Messages
Windows NT maintains a single system-message queue and any number of thread-message queues, one for each thread. Whenever the user moves the mouse, clicks the mouse buttons, or types at the keyboard, the device driver for the mouse or keyboard converts the input into messages and places them in the system-message queue. Windows removes the messages, one at a time, from the system-message queue, examines them to determine the destination window, and then posts them to the message queue of the thread that created the destination window. A thread's message queue receives all mouse and keyboard messages for the windows created by the thread. The thread removes messages from its queue and directs Windows NT to send them to the appropriate window procedure for processing. The system posts a message to a thread's message queue by filling an MSG structure and then copying it to the message queue. Information in the MSG structure includes the handle of the window for which the message is intended, the message identifier, the two message parameters, the message time, and the mouse-cursor position. A thread can post a message to its own message queue or to the queue of another thread by using the PostMessage or PostThreadMessage function.

Nonqueued Messages
Nonqueued messages are sent immediately to the destination window procedure, bypassing the system-message queue and thread-message queue. Windows typically sends nonqueued messages to notify a window of events that affect it. For example, when the user activates a new application window, Windows sends the window a series of messages, including WM_ACTIVATE, WM_SETFOCUS, and WM_SETCURSOR. These messages notify the window that it has been activated, that keyboard input is being directed to the window, and that the mouse cursor has been moved within the borders of the window. Certain Windows function calls can prompt nonqueued messages. For example, Windows sends the WM_WINDOWPOSCHANGED message after an application uses the SetWindowPos function to move a window.

danxuezx 2011-08-25
  • 打赏
  • 举报
回复
clear251 2011-08-25
  • 打赏
  • 举报
回复
SendMessage:不进队,主要是向一个或多个窗口发送一条消息,一直等到消息被处理之后才会返回。
PostMessage:进队,把一条消息放置到创建hWnd窗口的线程的消息队列中,该函数不等消息被处理就马上将控制返回。
sichuanwww 2011-08-25
  • 打赏
  • 举报
回复
进队的,就是PostMessage,就是需要消息队列来处理,是异步,
不进队,就是SendMessage,就是直接要求窗口过程函数来处理,一般用于同步
oyljerry 2011-08-25
  • 打赏
  • 举报
回复
进队的,就是PostMessage,就是需要消息队列来处理,是异步,
不进队,就是SendMessage,就是直接要求窗口过程函数来处理,一般用于同步
danxuezx 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 visualeleven 的回复:]
PostMessage/SendMessage
[/Quote]
支持部长,一语中的,言简意赅!
jixiang1983 2011-08-25
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 gibsonboy 的回复:]
深度解析VC中的消息
[/Quote]
++
canmeng 2011-08-25
  • 打赏
  • 举报
回复
这个问题比较有深度。好好学习。
gibsonboy 2011-08-25
  • 打赏
  • 举报
回复
Eleven 2011-08-25
  • 打赏
  • 举报
回复
PostMessage/SendMessage

16,470

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧