先在资源中插入menu资源,然后在类向导中添加OnContestMenu(CWnd* pWnd,CPoint point)函数代码很短如下:
1 void CMyDlg::OnContestMenu(CWnd* pWnd,CPoint point) 2 { 3 CMenu menu; 4 menu.LoadMenu(IDR_MENU); 5 6 CMenu * pop=menu.GetSubMenu(0) ;//0为索引号 7 8 POINT ptMouse; 9 GetCurSorPost(ptMouse); 10 pop->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,ptMouse.x,ptMouse.y); //鼠标位置和右键弹出 11 }
oK