对话框的菜单和控件无法使用COMMAND_UI
下面方法最简单、最实用的实现了。
//CXxxDlg.h ///////////////
//重载WM_MENUSELECT
afx_msg void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
//CXxxDlg.cpp ///////////////
//消息映射
ON_WM_MENUSELECT()
//消息映射结束
void CXxxDlg::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
//CDialog::OnMenuSelect(nItemID, nFlags, hSysMenu);
CCmdUI cmdUI;
CMenu* pMainMenu = GetMenu();
CMenu* pSubMenu = pMainMenu-> GetSubMenu(nItemID);
if(IsMenu(pSubMenu->GetSafeHmenu()))
{
cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();
for (UINT i = 0; i < cmdUI.m_nIndexMax;++i)
{
cmdUI.m_nIndex = i;
cmdUI.m_nID = pSubMenu->GetMenuItemID(i);
cmdUI.m_pMenu = pSubMenu;
cmdUI.DoUpdate(this, FALSE);
}
}
}
//十分简单,十分好用:)
本文地址:http://com.8s8s.com/it/it3057.htm