代码如下:
CMenu *oMenu,cc;
CMenu *pSubMenu;
CString strTmp; oMenu= AfxGetMainWnd()->GetMenu();
pSubMenu=oMenu->GetSubMenu(4);
oMenu->GetMenuString(1,strTmp,MF_BYPOSITION);
oMenu->EnableMenuItem(0,MF_BYPOSITION | MF_GRAYED); pSubMenu->GetMenuString(ID_APP_ABOUT,strTmp,MF_BYCOMMAND); //strTmp值也能正确取到 pSubMenu->EnableMenuItem(ID_APP_ABOUT,MF_BYCOMMAND | MF_GRAYED); 菜单有5个菜单项,为什么最后一行代码不产生效果呢? 而前面代码都有效
CMenu *oMenu,cc;
CMenu *pSubMenu;
CString strTmp; oMenu= AfxGetMainWnd()->GetMenu();
pSubMenu=oMenu->GetSubMenu(4);
oMenu->GetMenuString(1,strTmp,MF_BYPOSITION);
oMenu->EnableMenuItem(0,MF_BYPOSITION | MF_GRAYED); pSubMenu->GetMenuString(ID_APP_ABOUT,strTmp,MF_BYCOMMAND); //strTmp值也能正确取到 pSubMenu->EnableMenuItem(ID_APP_ABOUT,MF_BYCOMMAND | MF_GRAYED); 菜单有5个菜单项,为什么最后一行代码不产生效果呢? 而前面代码都有效
在主CPP文件里有类 CAboutDlg的声明,请注意以下注释:NOTE
BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
//{{AFX_MSG_MAP(CTestApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
框架开始生成的默认菜单UI都有默认的更新函数。你可以把资源里的菜单ID改一下试试看,应该就可以了
To l_b_q : 但是pSubMenu->CheckMenuItem(1,MF_BYPOSITION|MF_CHECKED); 是有效果的.
继续顶
BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
//{{AFX_MSG_MAP(CTestApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
这是架框预设的
在CMainFrame的构造函数中把m_bAutoMenuEnable设为FALSE,
CMainFrame::CMainFrame()
{
m_bAutoMenuEnable =FALSE;
}