CMFCPopupMenu的使用,以及子菜单按钮的激活与变灰
CMFCPopupMenu的使用,以及子菜单按钮的激活与变灰
1,定义鼠标左键响应函数
void CNetBroad3View::OnLButtonDown(CPoint point, int nUnitSn)
{
POINT ptScreen;
ptScreen = point;
ClientToScreen(&ptScreen);
CMenu menuPopUp;
menuPopUp.LoadMenuA(IDR_POPUP_EQUIP); //IDR_POPUP_EQUIP菜单ID
CMenu* pPopup = menuPopUp.GetSubMenu(0);
ASSERT(pPopup != NULL);
if (pPopup)
{
CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
pPopupMenu->SetAutoDestroy( TRUE );
if (pPopupMenu)
{
pPopupMenu->Create (this, ptScreen.x, ptScreen.y, pPopup->Detach (), TRUE);
pPopupMenu->SetForegroundWindow();
}
}
return TRUE;
}
2.激活子菜单按钮,首先定义函数
afx_msg void OnUpdateBroadBegin(CCmdUI* pCmdUI);
afx_msg void OnPopBroadBegin();
3.添加消息映射
ON_UPDATE_COMMAND_UI(IDC_BUTTON_PRINTINVOICE,OnEnablePrint)
ON_BN_CLICKED(IDC_BUTTON_PRINTINVOICE,OnPrintInvoice)
4.添加代码
void CNetBroad3View::OnUpdateBroadBegin(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE); //激活按钮
return;
}
void CNetBroad3View::OnPopBroadBegin()
{
MessageBox(_T("打印信息"));//按钮处理代码
return;
}