解决 不能通过CCmdUI *pCmdUI改变对话框菜单状态 的问题
来源:互联网 发布:linux sort命令 编辑:程序博客网 时间:2024/05/16 10:34
1.Add an ON_WM_INITMENUPOPUP entry to the message map:
- BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
- //}}AFX_MSG_MAP
- ON_WM_INITMENUPOPUP()
- END_MESSAGE_MAP()
2.Add a OnInitMenuPopup member function to your dialog box class and copy the following code (note that this code is taken largely from CFrameWnd::OnInitMenuPopup in WinFrm.cpp):
- void CTestDlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
- {
- 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;
- }
- }
- 解决 不能通过CCmdUI *pCmdUI改变对话框菜单状态 的问题
- 解决“不能通过CCmdUI *pCmdUI改变对话框菜单状态”的问题
- MFC对话框界面中使用CCmdUI对象更新菜单状态
- VC对话框运行后不能改变大小的问题
- 解决字体大小的改变影像显示对话框大小的问题
- MFC菜单操作CCmdUI
- 如何动态改变对话框的菜单。。。
- Andorid 网络状态改变监听不到问题的解决
- 用autoIt解决selenium不能操作对话框的问题
- 解决<span>标签内容改变,不能触发方法的问题
- 创建不能改变大小的对话框
- 创建不能改变大小的对话框
- 解决ubuntu14.04下eclipse 不能显示菜单的问题
- 解决ubuntu14.04下eclipse 不能显示菜单的问题
- MFC CCmdUI<控制菜单,工具栏,状态条,CDialogBar按钮,点击状态类>
- 解决Fragment的切换状态不能保存的问题
- 改变菜单勾选状态的方法
- 自定义AlertDialog对话框,包括解决对话框中edittext不能输入的问题
- ADF计算Table列总计
- 将CAS 单点登录协议由https改为http
- C#-如何释放非托管资源
- ASP.NET项目中调试时创建了多个端口的问题
- android一个登陆界面的设计
- 解决 不能通过CCmdUI *pCmdUI改变对话框菜单状态 的问题
- windows7 XP 如何安装netbeui协议
- JobTracker的操作权限管理——QueueManager
- 保护眼睛,调整你的电脑基色
- android 各种基本手势
- 资治通鉴,卷一百二十八,喝酒误事的鲁爽
- little endian and big endian
- NETBIOS/NETBEUI 协议 SAMBA
- 【Linux入门学习之】vi/vim编辑器必知必会