如何在我的WTL :: CListViewCtrl中而不是在父级中检测选择更改? [英] How to detect a selection change in my WTL::CListViewCtrl, and not in the parent?

查看:162
本文介绍了如何在我的WTL :: CListViewCtrl中而不是在父级中检测选择更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自己的WTL派生的listcontrol.

I have my own WTL derived listcontrol.

CPopupList : public CWindowImpl<CPopupList, WTL::CListViewCtrl>,

它工作正常,除了一件事:我想在选择更改时捕获通知.不在父窗口中(例如:如何检测CListCtrl选择更改?),但在CPopupList本身中,然后做一些事情.

It works fine, except one thing: I want to catch the notification when selection changes. Not in the parent window (like this: How to detect a CListCtrl selection change?) , but in the CPopupList itself, and then do some things.

实际上,我希望在当前选择的项目旁边显示一个小的提示窗口,作为当前项目的附加信息.就像VS在自动完成期间所做的一样,提供了有关功能/属性的更多信息.

Actually I want a small hint window next to the currently selected item to appear, as an additional info of the current item. Just like VS does during autocomplete, giving more info about the functions/properties.

有人给小费怎么做吗? 非常感谢.

Has anyone any tip how to do this? Thank you very much.

更新:

尝试:

BEGIN_MSG_MAP(CPopupList)
    REFLECTED_NOTIFY_CODE_HANDLER(LVN_ITEMCHANGED, OnListItemChanged)
    DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()

但是未调用OnListItemChanged(). 在父母中

But OnListItemChanged() is not called. In the parent the

REFLECT_NOTIFICATIONS()

已添加.

Update2-解决方案

我发现了问题:

父母的MSG_HANDLER:

The parent's MSG_HANDLER:

BEGIN_MSG_MAP(CEditorCtrl)
    MESSAGE_RANGE_HANDLER(WM_KEYFIRST,WM_KEYLAST,DelegateMessages)
    ...
    MESSAGE_
    ...
    NOTIFY_CODE_HANDLER(LVN_ITEMCHANGED,OnListItemChanged)
    CHAIN_MSG_MAP(parentType)
    ALT_MSG_MAP(11)
    COMMAND_HANDLER(IDC_PRINT_MONOCHROME,BN_CLICKED,OnPrintMonochromeButton)
    REFLECT_NOTIFICATIONS()
END_MSG_MAP()

将REFLECT_NOTIFICATIONS()移到ALT_MSG_MAP(11)上方,最后在控件中调用OnListItemChanged.

Moving the REFLECT_NOTIFICATIONS() above the ALT_MSG_MAP(11), and finally the OnListItemChanged is called in the control.

正确:

    REFLECT_NOTIFICATIONS()
    ALT_MSG_MAP(11)
    COMMAND_HANDLER(IDC_PRINT_MONOCHROME,BN_CLICKED,OnPrintMonochromeButton)

推荐答案

无论如何,通知消息都会发送给父级,您无法更改.您通常要做的是从父母到孩子的消息反射,以便[改进的]孩子可以照顾其祖先生成的通知.

The notification message is sent to parent anyway, you cannot change this. What you normally do is message reflection from parent to the child, so that [improved] child could take care of notification generated by its ancestor.

父窗口在消息映射上将具有反射处理程序:

The parent window will have a reflecting handler on the message map:

#include <atlcrack.h>

BEGIN_MSG_MAP_EX(CMyDialog)
    // ...
    REFLECT_NOTIFICATIONS()
END_MSG_MAP()

该控件将具有一个由控件父级反映的WM_NOTIFY通知的处理程序:

And the control will have a handler for WM_NOTIFY notifications reflected by control parent:

BEGIN_MSG_MAP_EX(CPopupList)
    // ...
    //MSG_OCM_CTLCOLORSTATIC(OnReflectedCtlColorStatic) // Reflected WM_CTLCOLORSTATIC
    MSG_OCM_NOTIFY(OnReflectedNotify) // Reflected WM_NOTIFY
    DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()

OnReflectedNotify是您可以在其中处理控件的通知的位置,但父级负责转发这些通知(无论是否经过自己的处理).

OnReflectedNotify is where you can handle the control's notifications, but the parent is responsible for forwarding them (with or without its own processing).

查看全文

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