如何将MFC消息重定向到另一个对象? [英] How to redirect MFC messages to another object?

查看:102
本文介绍了如何将MFC消息重定向到另一个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在从CWnd派生的类的实例中,是否可以将所有MFC消息转发(重定向)到另一个对象,而无需为每个可能的消息编写单独的处理程序和消息映射?具体来说,我想将所有未处理的WM_消息转发到另一个对象.如果这不可能,那么对象是否有可能侦听其他对象中发生的事件?如果可以帮助澄清我的问题,我可以提供详细信息.

In an instance of a class derived from CWnd, is it possible to forward (redirect) all MFC messages to another object, without writing separate handlers and message mappings for each possible message? Specifically, I'd like to forward all unhandled WM_ messages to another object. If this isn't possible, then is it possible for objects to listen to events that occur within other objects? I can provide details if that would help clarify my question.

谢谢.

推荐答案

您需要将目标对准比MFC低一点的目标.您应该覆盖窗口的PreTranslateMessage方法并直接处理消息.

You'll need to aim a little lower than MFC. You should override the PreTranslateMessage method of your window and process the messages directly.

一旦有了主消息循环,就可以选择应用程序处理哪些消息,以及将哪些消息发送/发布到另一个消息.如果您选择发送消息,我建议您使用SendMessageTimeout(...)

Once you have the main message loop, you can pick and choose which ones are handled by your app and which ones are Sent/Posted to another. If you choose to send the message, I'd recommend SendMessageTimeout(...)

这篇关于如何将MFC消息重定向到另一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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