void CXXX::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: 在此处添加消息处理程序代码
CMenu menu;
VERIFY(menu.LoadMenu(IDR_POPMENU));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,pWndPopupOwner);
}
上面的代码可在 vs下添加右键弹出菜单,在窗口的事件中找到ContextMenu消息,添加即可,在资源里添加菜单项命名为IDR_POPMENU。
选中资源菜单的某项,右击,添加事件处理程序即可,响应菜单项。