How to redirect MFC messages to another object?(如何将 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 消息重定向到另一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 MFC 消息重定向到另一个对象?


基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01