...........................................................

解决方案 »

  1.   

    可以使用,但是一定要先选中树的情况下才会生效。
    所以就有了
    ON_WM_CONTEXTMENU()
    这个消息这个例子在VS2008以上版本带BCG风格的VS多文档中有void CClassView::OnContextMenu(CWnd* pWnd, CPoint point)
    {
    CTreeCtrl* pWndTree = (CTreeCtrl*)&m_wndClassView;
    ASSERT_VALID(pWndTree); if (pWnd != pWndTree)
    {
    CDockablePane::OnContextMenu(pWnd, point);
    return;
    } if (point != CPoint(-1, -1))
    {
    // Select clicked item:
    CPoint ptTree = point;
    pWndTree->ScreenToClient(&ptTree); UINT flags = 0;
    HTREEITEM hTreeItem = pWndTree->HitTest(ptTree, &flags);
    if (hTreeItem != NULL)
    {
    pWndTree->SelectItem(hTreeItem);
    }
    } pWndTree->SetFocus();
    CMenu menu;
    menu.LoadMenu(IDR_POPUP_SORT); CMenu* pSumMenu = menu.GetSubMenu(0); if (AfxGetMainWnd()->IsKindOf(RUNTIME_CLASS(CMDIFrameWndEx)))
    {
    CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu; if (!pPopupMenu->Create(this, point.x, point.y, (HMENU)pSumMenu->m_hMenu, FALSE, TRUE))
    return; ((CMDIFrameWndEx*)AfxGetMainWnd())->OnShowPopupMenu(pPopupMenu);
    UpdateDialogControls(this, FALSE);
    }
    }
    注意看他使用point然后用tree对象的HitTest来触发选中的。楼主也可以尝试