无法抓住TVN_SELCHANGED

时间:2012-05-31 09:25:14

标签: c++ mfc treecontrol

我在对话框中有一个CTreeCtrl并捕获TVN_SELCHANGED消息,但执行不会进入处理程序。有什么不对? 我的代码:

BEGIN_MESSAGE_MAP(CMaterParamExtDlg, CDialog)
   ON_NOTIFY(TVN_ITEMCHANGING, IDC_MATERIAL_PROP_TREE, OnSelChangingTreeCtrl)
   ON_NOTIFY(TVN_ITEMCHANGED, IDC_MATERIAL_PROP_TREE, OnSelChangedTreeCtrl)
END_MESSAGE_MAP()

void CMaterParamExtDlg :: OnSelChangedTreeCtrl (NMHDR* pNMHDR, LRESULT* pResult) 
{
    if (m_TreeCtrl != 0)
    {
        HTREEITEM treeitem = m_TreeCtrl->GetSelectedItem();
        CString treeitemtext = m_TreeCtrl->GetItemText(treeitem);

        MessageBox(treeitemtext);
    }

    *pResult = 0;
}

void CMaterParamExtDlg :: OnSelChangingTreeCtrl (NMHDR* pNMHDR, LRESULT* pResult)
{
    if (m_TreeCtrl != 0)
    {
        HTREEITEM treeitem = m_TreeCtrl->GetSelectedItem();
        CString treeitemtext = m_TreeCtrl->GetItemText(treeitem);

        MessageBox(treeitemtext);
    }

    *pResult = 0;
}

我尝试使用断点来查看执行是否进入处理程序但没有任何反应。

树控制属性:

CONTROL         "",IDC_MATERIAL_PROP_TREE,"SysTreeView32",TVS_HASBUTTONS 
| TVS_HASLINES | TVS_LINESATROOT | TVS_DISABLEDRAGDROP 
| TVS_TRACKSELECT | WS_BORDER | WS_HSCROLL | WS_TABSTOP,4,4,115,218

1 个答案:

答案 0 :(得分:3)

非常简单。使用TVN_SELCHANGED而不是TVN_ITEMCHANGED。同样适用于TVN_ITEMCHANGING。