博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VC 菜单OnUPdate事件
阅读量:4500 次
发布时间:2019-06-08

本文共 2491 字,大约阅读时间需要 8 分钟。

解决弹出菜单OnUpdata事件无效,重载窗体事件:OnInitMenuPopup

void CDialog::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu) { //CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu); // TODO: 在此处添加消息处理程序代码 ASSERT(pPopupMenu != NULL); // Check the enabled state of various menu items. CCmdUI state; state.m_pMenu = pPopupMenu; ASSERT(state.m_pOther == NULL); ASSERT(state.m_pParentMenu == NULL); // Determine if menu is popup in top-level menu and set m_pOther to // it if so (m_pParentMenu == NULL indicates that it is secondary popup). HMENU hParentMenu; if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu) state.m_pParentMenu = pPopupMenu; // Parent == child for tracking popup. else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL) { CWnd* pParent = this; // Child windows don't have menus--need to go to the top! if (pParent != NULL && (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL) { int nIndexMax = ::GetMenuItemCount(hParentMenu); for (int nIndex = 0; nIndex < nIndexMax; nIndex++) { if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu) { // When popup is found, m_pParentMenu is containing menu. state.m_pParentMenu = CMenu::FromHandle(hParentMenu); break; } } } } state.m_nIndexMax = pPopupMenu->GetMenuItemCount(); for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax; state.m_nIndex++) { state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex); if (state.m_nID == 0) continue; // Menu separator or invalid cmd - ignore it. ASSERT(state.m_pOther == NULL); ASSERT(state.m_pMenu != NULL); if (state.m_nID == (UINT)-1) { // Possibly a popup menu, route to first item of that popup. state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex); if (state.m_pSubMenu == NULL || (state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 || state.m_nID == (UINT)-1) { continue; // First item of popup can't be routed to. } state.DoUpdate(this, TRUE); // Popups are never auto disabled. } else { // Normal menu item. // Auto enable/disable if frame window has m_bAutoMenuEnable // set and command is _not_ a system command. state.m_pSubMenu = NULL; state.DoUpdate(this, FALSE); } // Adjust for menu deletions and additions. UINT nCount = pPopupMenu->GetMenuItemCount(); if (nCount < state.m_nIndexMax) { state.m_nIndex -= (state.m_nIndexMax - nCount); while (state.m_nIndex < nCount && pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID) { state.m_nIndex++; } } state.m_nIndexMax = nCount; } }

转载于:https://www.cnblogs.com/whisht/archive/2012/01/11/2319683.html

你可能感兴趣的文章
XCode: duplicate symbol 解决方案
查看>>
iOS状态栏设置详解!
查看>>
编程习惯1
查看>>
【读书笔记】iOS-给模拟器相册增加图片
查看>>
ActionMapping、ActionForward笔记
查看>>
Linux:xargs命令详解
查看>>
明天你好
查看>>
float浮点数的四舍五入
查看>>
QQ消息记录、接收文件、图片、拍照照片等保存位置
查看>>
IOC与AOP介绍
查看>>
关于求最大公约数
查看>>
Git常用命令学习总结
查看>>
【转载】C#通过Rows.Count属性获取总行数
查看>>
【转载】通过百度站长平台查看网站搜索流量及关键字
查看>>
【转载】Visual Studio2017如何打包发布Winform窗体程序
查看>>
【转载】通过搜狗站长平台手动向搜狗搜索提交死链
查看>>
【转载】通过搜狗站长平台手动向搜狗搜索提交文章加快收录
查看>>
【转载】通过百度站长平台提交网站死链
查看>>
【转载】通过搜狗站长平台提交网站域名变更后的文章地址
查看>>
【转载】Visual Studio2017中如何设置解决方案中的某个项目为启动项目
查看>>