TVN_SELCHANGING not received

2019-08-12 16:45发布

问题:

I have a WTL81 app. CMainFrame has a child CPaneContainer, that has a child window CTreeViewCtrl. The problem is CTreeViewCtrl doesn't receive TVN_SELCHANGING message.

I have "spied" CTreeViewCtrl and his parent (CPaneContainer) and no notification code is received.

CMainFrame is implemented from public CFrameWindowImpl<CMainFrame>

CPaneContainer is implemented like this

class PaneContainerReflectNotif : public CPaneContainer 
{
    BEGIN_MSG_MAP(PaneContainerReflectNotif)
        CHAIN_MSG_MAP(CPaneContainer)
        REFLECT_NOTIFICATIONS()
    END_MSG_MAP()
};

Tree is implemented like this

class MyTreeView : 
    public CWindowImpl<CatalogTreeView, CTreeViewCtrl>,
    public CCustomDraw<CatalogTreeView>,
    public CTheme

   ...

BEGIN_MSG_MAP_EX(MyTreeView )
    MSG_WM_CREATE(OnCreate)
    MSG_WM_DESTROY(OnDestroy)
    REFLECTED_NOTIFY_CODE_HANDLER_EX(NM_DBLCLK, OnDblClick)
    REFLECTED_NOTIFY_CODE_HANDLER_EX(TVN_ITEMEXPANDING, OnItemExpanding)
    REFLECTED_NOTIFY_CODE_HANDLER_EX(TVN_SELCHANGING, OnSelChanged)

OnDblClick - works fine
OnItemExpanding - works fine
OnSelChanged - doesn't work

any ideas on what could be the problem ?

回答1:

Solved. My problem was that treeview was multi-selct and that kind of tree doesn't send TVN_SELCHANGING notifications



回答2:

You have not mentioned why do you need TVN_SELCHANGING. The event gets fired when the tree nodes are getting changed, and another tree node is being selected.

As an alternative, you might try TVN_SELCHANGED or HitTest( ). I am providing a MFC link .. http://msdn.microsoft.com/en-us/library/x0w7ft34.aspx



标签: c++ winapi atl wtl