在MFC中创建上下文相关菜单

时间:2014-05-26 22:11:20

标签: c++ mfc

我找到了这个教程http://msdn.microsoft.com/en-us/vstudio/Cc514027来帮助我创建一个菜单。

我一步一步地按照教程进行操作。我有两个红色的盒子,但我无法右键单击这两个方框来显示菜单。

当我调试时,我最终得到错误代码C2084:function' void CContextMenusView :: OnContextMenu(CWnd *,CPoint)'已经有一个身体。

  // CContextMenusView message handlers
   void CContextMenusView::OnContextMenu(CWnd* /*pWnd*/, CPoint point)

{     // TODO:在这里添加你的消息处理程序代码

CMenu PopupMenu;
CPoint ptClient;
m_nBox = -1;

ptClient = point;
ScreenToClient(&ptClient);

if (rect1.PtInRect(ptClient))
    m_nBox = 0;
else if (rect2.PtInRect(ptClient))
    m_nBox = 1;

if (m_nBox != -1)
{
    if (PopupMenu.LoadMenu(IDR_CONTEXTMENU))
    {
        CMenu* pPopupMenu = PopupMenu.GetSubMenu(0);
        if (point.x == -1 && point.y == -1)
        {
            point.x = 5;
            point.y = 5;
            ClientToScreen(&point);
        }
        pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
            point.x, point.y, this);
    }
}

}

0 个答案:

没有答案