Windows消息处理 [英] Windows message handling

查看:113
本文介绍了Windows消息处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

窗口向自身发布消息是一种好习惯吗?
如果窗口向自身发送消息,这是否意味着该窗口过程将被递归调用?

我对SendMessage()的描述感到困惑:该函数将调用指定窗口的窗口过程,并且在窗口过程处理完消息之前不会返回 .如果在同一窗口过程中发生这种情况,则整个线程必须是一个庞大的递归调用序列.

Is it a good practice for a window to post messages to itself?
If a window sends a message to itself, doesn''t that mean that the window procedure gets called recursively?

I am getting confused by the description of SendMessage(): "The function calls the window procedure for the specified window and does not return until the window procedure has processed the message". If this is happening within the same window procedure, the entire thread must be one huge sequence of recursive calls.

推荐答案

它是这样的:当程序发送时向其自己的窗口发送消息,这是完全有效的操作.下次调度程序在messge循环中检查是否有要处理的消息时,将使用相应的参数调用WindowsProc.仅当将收到的相同消息重新发送到其自己的窗口时,才会发生使程序停止工作的递归.您必须非常警惕自己的操作,因为递归可能需要完成多个步骤:

It''s like this: When a program sends a message to it''s own window this is a totally valid operation. Next time the dispatcher checks in the messge loop if there are messages to process, the WindowsProc is called with the corresponding parameters. Recursion that will make your program stop working will only happen if the same message that was received would be resent to its own window. You''ll have to be very wary of what you are doing as the recursion might take more than one step:

Received Message | Sent Message
-------------------------------
       A         |      B
       B         |      C
       C         |      A



您可以轻松地发现将任何消息A,B或C发送到Windows WndProc时发生的循环.

最好的问候,

—MRB



You can easily spot the loop occuring when any message A, B or C was sent to the windows WndProc.

Best Regards,

—MRB


这篇关于Windows消息处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆