对话框中菜单的标记
来源:互联网 发布:linux vi文件编辑命令 编辑:程序博客网 时间:2024/05/27 21:11
转自:http://blog.163.com/lvan100@yeah/blog/static/68117214201073121815150/
http://support.microsoft.com/kb/242577/en-us
对于文档类创建的应用程序来说,添加复选标记很简单。
在类向导中添加命令,菜单的相应ID加Update_Command_UI消息相应函数,
void CVeCountDlg::OnUpdateOpen(CCmdUI *pCmdUI)
{
// TODO: 在此添加命令更新用户界面处理程序代码
pCmdUI->SetCheck(m_bCheckOpen);
}
仅仅一个SetCheck()而已。
可是对于对话框而言,就大大的麻烦了。解决办法是什么呢?
添加ON_WM_INITMENUPOPUP 处理消息
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;
}
}
其他与菜单相同即可
- 对话框中菜单的标记
- vS2010中标记菜单
- 【win32】标记菜单与对话框背景色
- MFC的对话框中添加右键菜单
- 在对话框中创建菜单以及快捷菜单的步骤
- 对话框的菜单 ON_UPDATE_COMMAND_UI
- 对话框的菜单操作
- mfc 为对话框工程添加工具条时,实现工具条的按下状态与菜单标记的同步实例
- 在对话框中添加菜单
- 更新处理函数在对话框的菜单中不能工作
- 屏蔽VC对话框中点击FLASH弹出的右键菜单
- WinCE中为基于对话框的程序动态增加菜单
- 为菜单条加选中标记
- win32 单选标记的菜单
- html中dl、dt、dd标记的使用实现菜单显示|隐藏
- 对话框与菜单的使用
- qt中添加资源文件以及添加菜单图标、工具栏中菜单的快捷方式、窗口以及对话框的icon
- qt中添加资源文件以及添加菜单图标、工具栏中菜单的快捷方式、窗口以及对话框的icon
- 配置mongodb分片群集(sharding cluster)
- 文件操作与ASCII文件流
- Qt 的几个核心机制总结之 事件管理
- Memcached 配置
- 【ACM Steps】Wolf and Rabbit
- 对话框中菜单的标记
- 程序员的数学--笔记
- 探索推荐引擎内部的秘密,第 2 部分: 深入推荐引擎相关算法 - 协同过滤
- ultraedit设置默认打开格式
- 关于UI_USER_INTERFACE_IDIOM() & UIDevice.model
- VC+ADO 连接ACCESS和SQL SERVER的方法
- 网格计算、集群计算、云计算、分布式计算(一)
- WPF App下无法多个窗口按序ShowDialog
- ScrollView里面放入多个子控件