gpt4 book ai didi

c++ - 当我有控件定义的 ON_NOTIFY_REFLECT 时,ON_NOTIFY 在我的对话框中不起作用

转载 作者:行者123 更新时间:2023-11-30 02:42:12 27 4
gpt4 key购买 nike

在我的 CTreeCtrl 派生类中,我作用于 TVN_ITEMEXPANDED:

ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, &OnTVNItemExpanded)

在控件的父对话框中,我也想对相同的通知 TVN_ITEMEXPANDED 采取行动,

ON_NOTIFY(TVN_ITEMEXPANDED, IDC_ELEMENT_TREE, &OnTVNItemExpanded)

但是,只有控件类的 OnTVNItemExpanded 方法被调用,我的对话框从来没有被调用。我使用了两个断点并在两种方法中都看到了所需的行为(或缺少所需的行为),以验证是否仅调用了控件类的方法,而不是我的对话框的方法。

但是,如果我从 CTreeCtrl 派生的 BEGIN_MESSAGE_MAP 中注释掉 ON_NOTIFY_REFLECT,那么我的对话框的方法就会被调用!?!

为什么通知不能同时到我的控件和我的对话框?!?

最佳答案

ON_NOTIFY_REFLECT 覆盖 ON_NOTIFY,但您可以使用 ON_NOTIFY_REFLECT_EX 代替,它让您的回调决定消息是否应该传递给父级.

参见 Message Reflection for Windows Controls更详细的解释:

If, in your parent window class, you supply a handler for a specific WM_NOTIFY message or a range of WM_NOTIFY messages, your handler will be called only if the child control sending those messages does not have a reflected message handler through ON_NOTIFY_REFLECT(). If you use ON_NOTIFY_REFLECT_EX() in your message map, your message handler may or may not allow the parent window to handle the message. If the handler returns FALSE, the message will be handled by the parent as well, while a call that returns TRUE does not allow the parent to handle it. Note that the reflected message is handled before the notification message.

关于c++ - 当我有控件定义的 ON_NOTIFY_REFLECT 时,ON_NOTIFY 在我的对话框中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27325358/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com