//加载"选择"右键菜单
CMenu menu;
menu.LoadMenu(IDR_MENU1); CMenu* pPopupMenu=menu.GetSubMenu(0);
CPoint pt;
GetCursorPos(&pt);<<<<<<<<<<<<<<<<<注意本行
pPopupMenu->TrackPopupMenu(TPM_RIGHTBUTTON,pt.x,pt.y,this);
//菜单弹出后销毁对象
menu.DestroyMenu();
pPopupMenu->DestroyMenu();
pPopupMenu=NULL;

解决方案 »

  1.   

    在TrackPopupMenu之前加上ScreenToClient(&pt);
      

  2.   

    prog_st(st)请解释一下吧.上面的point为什么不能?
      

  3.   

    Example// The code fragment shows how to get the File menu from the
    // application window and displays it as a floating popup menu
    // when the right mouse button is clicked in view.
    // CMyView is a CView-derived class.
    void CMyView::OnRButtonDown(UINT nFlags, CPoint point) 
    {
       CView::OnRButtonDown(nFlags, point);   CMenu* menu_bar = AfxGetMainWnd()->GetMenu();
       CMenu* file_menu = menu_bar->GetSubMenu(0);    
       ASSERT(file_menu);   file_menu->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, point.x, 
          point.y, this);
    }msdn的例子
    我忘了传进来的point是否屏幕坐标.如果是客户区坐标
    那就ClientToScreen(&pt);因为 TrackPopupMenu(TPM_RIGHTBUTTON,pt.x,pt.y,this);
    里的x和y是屏幕坐标
    xSpecifies the horizontal position in screen coordinates of the pop-up menu. Depending on the value of the nFlags parameter, the menu can be left-aligned, right-aligned, or centered relative to this position.ySpecifies the vertical position in screen coordinates of the top of the menu on the screen.
      

  4.   

    呵呵,我写反了,应该是ClientToScreen(&point);