急,简单的问题,在线等,有关基于对话框的弹出式菜单问题!!!!

tiancai1 2006-08-23 04:27:05
我的菜单是弹出式的二级菜单,我的第二级菜单上有四个项,我想实现任意时刻只有一个项前面打勾,如果我选择另一个则原先的那个没有勾,而被点击的项前面带勾。
怎么实现,用什么函数。
...全文
245 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiancai1 2006-08-24
  • 打赏
  • 举报
回复
谢谢楼上的所有人!!揭贴。
tiancai1 2006-08-24
  • 打赏
  • 举报
回复
骇,问题解决了,我老想在OnUpdateXXX(CCmdUI* )在这函数里面改变状态标志,骇有是人的脑子会短路的。
kelvin0009 2006-08-24
  • 打赏
  • 举报
回复
还要记住如果是dialog-based的程序,对话框上的菜单要想改变状态,还要在MESSAGE MAP中添加ON_WM_INITMENUPOPUP(),并加入如下代码:
void CXXXDlg::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;
}
}

后才可以实现改变菜单项的状态.
ringphone 2006-08-24
  • 打赏
  • 举报
回复
CMenu::CheckMenuRadioItem( UINT nIDFirst, UINT nIDLast, UINT nIDItem, UINT nFlags );或
::CheckMenuRadioItem(HMENU hmenu UINT nIDFirst, UINT nIDLast, UINT nIDItem, UINT nFlags )
nIDFirst,nIDLast为这一组菜单项的ID范围
Elysium 2006-08-24
  • 打赏
  • 举报
回复
选中菜单ID,右键类向导,Message Maps,Messages中选中UPDATE_COMMAND_UI,Add Function即可
kelvin0009 2006-08-24
  • 打赏
  • 举报
回复
不用自己写消息映射
tiancai1 2006-08-24
  • 打赏
  • 举报
回复
可是这个OnUpdateXXX(CCmdUI* )函数是只要我改变菜单的项就会响应的,或者打开第二级菜单我把我要的是要点击后才产生我要的效果的啊,是不是的自己写消息映射。
kelvin0009 2006-08-23
  • 打赏
  • 举报
回复
定义四个BOOL变量例如m_bMenu1,m_bMenu2,m_bMenu3,m_bMenu4
void CTestDlg::OnUpdateMenu1(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_bMenu1);

}

void CTestDlg::OnMenu1()
{
m_bMenu1 = !m_bMenu1;
m_bMenu2 = FALSE;
m_bMenu3 = FALSE;
m_bMenu4 = FALSE;
}
yangsky971 2006-08-23
  • 打赏
  • 举报
回复
点哪个的时候就设上这个,SetCheck(1) ,其他的就都SetCheck()就可以了
Elysium 2006-08-23
  • 打赏
  • 举报
回复
可以使用一个通用的过程
ON_COMMAND_RANGE
ON_UPDATE_COMMAND_UI_RANGE
wangyu_2004520 2006-08-23
  • 打赏
  • 举报
回复
没有错
SetCheck(1) 表示 :选中
SetCheck()表示 :清除
ssbelle 2006-08-23
  • 打赏
  • 举报
回复
你自己通过判断来设定菜单的状态
在菜单的更新函数里
OnUpdateXXX(CCmdUI* pCmdUI)
pCmdUI->SetCheck(1);

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧