VC2012创建弹出式菜单
首先为视类添加鼠标右键单击处理函数,添加如下代码,
void CMFCApplication1View::OnRButtonDown(UINT nFlags, CPoint point)
{// TODO: 在此添加消息处理程序代码和/或调用默认值CView::OnRButtonDown(nFlags, point);CMenu menu;menu.CreatePopupMenu();menu.AppendMenuW(0, 50001, _T("蓝色"));menu.AppendMenuW(0, 50002, _T("红色"));menu.AppendMenuW(0, 50003, _T("黄色"));menu.TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN, point.x, point.y, this);
}
运行,效果如下;