2

我在对话框中有一个 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
4

1 回答 1

4

Pretty simple. Use TVN_SELCHANGED instead of TVN_ITEMCHANGED. Ditto for TVN_ITEMCHANGING.

于 2012-05-31T14:49:08.893 回答