对话框类中添加消息函数(Messages) WM_OnContextMenu
afx_msg void OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/); //函数声明
void CBarView::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/) //函数体
{
// TODO: Add your message handler code here
CMenu menu;
menu.LoadMenu(IDR_RIGHTMENU);
CMenu* pop=menu.GetSubMenu(0);
POINT ptMouse;
GetCursorPos(&ptMouse);
pop->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,ptMouse.x,ptMouse.y, this);
}