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

查看:15
本文介绍了如何将 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天全站免登陆