如何使弹出式菜单项中的弹出式菜单项变灰?

mhj1232 2009-09-08 04:40:26
我建了个菜单,在菜单栏下还有一个弹出式菜单,该弹出式菜单有两个菜单项,我用了以下方法都无法使这两个菜单项变灰。
1.GetMenu()->GetSubMenu(2)->GetSubMenu(0)->EnableMenuItem(0,MF_GRAYED|MF_BYPOSITION);该方法Debug错误
2.GetMenu()->GetSubMenu(2)->EnableMenuItem(菜单ID,MF_GRAYED|MF_BYPOSITION);无反应
...全文
175 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
beniii011 2010-03-18
  • 打赏
  • 举报
回复
xiexie ,i would like to see the solution.
mhj1232 2009-09-08
  • 打赏
  • 举报
回复
有必要搞那么复杂吗?
yuhudie203 2009-09-08
  • 打赏
  • 举报
回复
基于对话框的要添加相应的代码


相应 OnInitMenuPopup虚函数
virtual void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);
然后添加如下代码
void CDrawRate::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;
}
}

mhj1232 2009-09-08
  • 打赏
  • 举报
回复
我用的基于对话框的
dirdirdir3 2009-09-08
  • 打赏
  • 举报
回复
直接在mainframe里面onupdatexxx里返回disable
mhj1232 2009-09-08
  • 打赏
  • 举报
回复
行不通。要求变灰的子菜单是弹出式菜单中的弹出式菜单的第一项。
yuhudie203 2009-09-08
  • 打赏
  • 举报
回复
GetMenu()->GetSubMenu(2)->EnableMenuItem(菜单ID,MF_GRAYED|MF_BYCOMMAND);试试
或者
GetMenu()->GetSubMenu(2)->EnableMenuItem(0,MF_GRAYED|MF_BYPOSITION);

15,978

社区成员

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

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