你处理一下该控件的WM_LBUTTONDOWN消息,再用HitTest就可以知道用户选择了哪一项了。 example: UINT uFlags; HTREEITEM hItem = pmyTreeCtrl->HitTest(myPoint, &uFlags);if ((hItem != NULL) && (TVHT_ONITEM & uFlags)) { pmyTreeCtrl->Select(hItem, TVGN_CARET); } uFlags可以是: TVHT_ABOVE Above the client area. TVHT_BELOW Below the client area. TVHT_NOWHERE In the client area, but below the last item. TVHT_ONITEM On the bitmap or label associated with an item. TVHT_ONITEMBUTTON On the button associated with an item. TVHT_ONITEMICON On the bitmap associated with an item. TVHT_ONITEMINDENT In the indentation associated with an item. TVHT_ONITEMLABEL On the label (string) associated with an item. TVHT_ONITEMRIGHT In the area to the right of an item. TVHT_ONITEMSTATEICON On the state icon for a tree-view item that is in a user-defined state. TVHT_TOLEFT To the left of the client area. TVHT_TORIGHT To the right of the client area 自己看MSDN吧
example:
UINT uFlags;
HTREEITEM hItem = pmyTreeCtrl->HitTest(myPoint, &uFlags);if ((hItem != NULL) && (TVHT_ONITEM & uFlags))
{
pmyTreeCtrl->Select(hItem, TVGN_CARET);
}
uFlags可以是:
TVHT_ABOVE Above the client area.
TVHT_BELOW Below the client area.
TVHT_NOWHERE In the client area, but below the last item.
TVHT_ONITEM On the bitmap or label associated with an item.
TVHT_ONITEMBUTTON On the button associated with an item.
TVHT_ONITEMICON On the bitmap associated with an item.
TVHT_ONITEMINDENT In the indentation associated with an item.
TVHT_ONITEMLABEL On the label (string) associated with an item.
TVHT_ONITEMRIGHT In the area to the right of an item.
TVHT_ONITEMSTATEICON On the state icon for a tree-view item that is in a user-defined state.
TVHT_TOLEFT To the left of the client area.
TVHT_TORIGHT To the right of the client area
自己看MSDN吧
{
switch(message)
{
case WM_NOTIFY:
{
LPNMHDR lpnmh = (LPNMHDR) lParam;
TVHITTESTINFO ht = {0};
if((lpnmh->code == NM_CLICK) && (lpnmh->idFrom == IDC_TREE))
{
DWORD dwpos = GetMessagePos();
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
MapWindowPoints( this , &ht.pt, 2); m_Tree.HitTest(&ht);
if(TVHT_ONITEMSTATEICON & ht.flags)
{
PostMessage( UM_CHECKSTATECHANGE, 0, (LPARAM)ht.hItem);
}
}
}
break;
case UM_CHECKSTATECHANGE:
{
HTREEITEM pItem = (HTREEITEM)lParam;
int j = (int)m_Tree.GetItemData(pItem);
if(j == 0)
MessageBox("root is selected !");
}
break;
}
return CDialog::WindowProc(message, wParam, lParam);}在if(TVHT_ONITEMSTATEICON & ht.flags)这里,没有进入执行