怎样使右键菜单也能变灰、打勾

蘭斯洛特 2006-01-06 09:52:45
右键弹出的菜单可以响应OnUpdate×××,这里用pCmdUI->Enable、pCmdUI->SetCheck没有效果,虽然pCmdUI->Enable(FALSE)确实禁止了菜单项响应消息但菜单项没有变灰,就像普通菜单那样,而且SetCheck也没有效果,请问该怎么办能作出像系统菜单那样,有时系统右键菜单里的 粘贴 就是灰的表示不可用。谢谢
...全文
806 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
javar2000 2006-05-28
  • 打赏
  • 举报
回复
void CDXCaptureDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);

CMenu* pPopup = pPopupMenu;
pPopup->EnableMenuItem(ID_MENUITEM_Start, MF_GRAYED);
pPopup->EnableMenuItem(ID_MENUITEM_Stop, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
}
清歌谁与和 2006-01-08
  • 打赏
  • 举报
回复
void CTestDlg::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu menu, *popup;
// 装入菜单
menu.LoadMenu(IDR_MENU_CONTEXT);
popup=menu.GetSubMenu(0);

popup->EnableMenuItem (ID_EDIT_UNDO, MF_GRAYED);//使菜单失效

//popup->EnableMenuItem (ID_EDIT_UNDO, MF_ENABLED);//使菜单有效


// 显示菜单
popup->TrackPopupMenu (TPM_LEFTALIGN|TPM_LEFTBUTTON,
point.x, point.y, this);
}

蘭斯洛特 2006-01-06
  • 打赏
  • 举报
回复
lixiaosan的方法奏效
不知还有没有别的方法呢
蘭斯洛特 2006-01-06
  • 打赏
  • 举报
回复
Seu_why的方法虽然简单,可惜我是基于对话框的程序啊。555...
lixiaosan的方法长了点,感觉有些杀鸡用牛刀了,先试试
Seu_why 2006-01-06
  • 打赏
  • 举报
回复
CMainFrame::CMainFrame()
{
this->m_bAutoMenuEnable = FALSE;
}
m_bAutoMenuEnable的值取消对无消息处理函数菜单的状态限制.
lixiaosan 2006-01-06
  • 打赏
  • 举报
回复
添加
afx_msg void OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu);

ON_WM_INITMENUPOPUP()

void CTest6Dlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)

{

CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);



// TODO: Add your message handler code here

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;

}

}

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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