如何将 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(...)
相关文章