主要是用TrackPopupMenu才实现。
新建一个菜单资源IDR_MENU1,然后为View类添加OnContextMenu类添加消息,添加如下代码:
void CRMenuView::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
CMenu m_popMenu;
m_popMenu.LoadMenu(IDR_MENU1);
CMenu* pSubMenu=m_popMenu.GetSubMenu(0);
pSubMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,point.x,point.y,this);
}