你应该处理 OnContextMenu()而不是OnRButtonDown()

解决方案 »

  1.   

    我试过的了,在OnContextMenu()中右击连快捷菜单都不能创建,要双击右键才行,又不知是何原因。
      

  2.   

    void CCWDeptTreeView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) 
    {
    // TODO: Add your control notification handler code here
    UNREFERENCED_PARAMETER(pNMHDR);
    // TODO: Add your control notification handler code here
    CTreeCtrl& ctlTree = (CTreeCtrl&) GetTreeCtrl();
    HTREEITEM itemTree; UINT nFlags;
    CPoint curPoint;
    GetCursorPos(&curPoint);
    ScreenToClient(&curPoint);
    itemTree= ctlTree.HitTest(curPoint, &nFlags);
    if (itemTree!=NULL)
    ctlTree.Select(itemTree,TVGN_CARET);
    CPoint posMouse;
    GetCursorPos(&posMouse); CMenu menu;
    menu.LoadMenu(IDR_CWDEPT_VIEW);
    menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
    posMouse.x, posMouse.y ,::AfxGetMainWnd());  *pResult = 0;
    }