我新建了一个Windows Explorer风格的多文档视,然后从左视中加入了OnContestMenu来从左视中弹出菜单,可是弹出的情况很不稳定,双击才能弹出.请问各位高手,这是为什么,是不是MFC的一个BUG?

解决方案 »

  1.   

    应该不是吧,关于这个消息的说明是“Called when the user right clicks in the window”,请注意是“clicks”,不是“click”
      

  2.   

    void CLeftView::OnContextMenu(CWnd*, CPoint point)
    { // CG: This block was added by the Pop-up Menu component
    {
    if (point.x == -1 && point.y == -1){
    //keystroke invocation
    CRect rect;
    GetClientRect(rect);
    ClientToScreen(rect); point = rect.TopLeft();
    point.Offset(5, 5);
    } CMenu menu;
    VERIFY(menu.LoadMenu(CG_IDR_POPUP_LEFT_VIEW)); CMenu* pPopup = menu.GetSubMenu(0);
    ASSERT(pPopup != NULL);
    CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD)
    pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
    pWndPopupOwner);
    }
    }
      

  3.   

    正常的情况下你的鼠标消息,首先是被左边的视图中的CTreeCtrl拦截的!
      

  4.   

    可是我没有重载CTreeCtrl中的任何函数呀!
      

  5.   

    使用SPY++观察CTreeView的消息,发现右键按下时不响应OnContextMenu消息。
    可以添加TreeView的OnRightBtnDown消息,在里面弹出菜单,且在TreeView类中添
    加每个菜单项的响应函数。
      

  6.   

    to:GZComplier,你的方法很用,可是对于这个消息的传递过程,还是不清楚。
    to:psusong(人类失去指针,世界将会怎样?) 能不能说一说消息被CTreeCtrl拦截后,下一步的传递过程