//do you want to check menu item enable or disable? you can try this way,such as CMenu mnShellPop,*mnShellContext; mnShellPop.LoadMenu(IDR_TEST_MENU); mnShellContext=mnShellPop.GetSubMenu(0); if (!m_bAutoStart) { mnShellContext->CheckMenuItem(ID_SLCCEX_AUTORUN, MF_UNCHECKED | MF_BYCOMMAND); } else { mnShellContext->CheckMenuItem(ID_SLCCEX_AUTORUN, MF_CHECKED | MF_BYCOMMAND); }
m_pMenu = AfxGetMainWnd()->GetMenu();m_pMenu->CheckMenuItem(ID,nCheck)UINT CheckMenuItem( UINT nIDCheckItem, UINT nCheck );nCheck :MF_BYCOMMAND Specifies that the parameter gives the command ID of the existing menu item. This is the default.MF_BYPOSITION Specifies that the parameter gives the position of the existing menu item. The first item is at position 0.MF_CHECKED Acts as a toggle with MF_UNCHECKED to place the default check next to the item.MF_UNCHECKED Acts as a toggle with MF_CHECKED to remove a check next to the item.
CMenu mnShellPop,*mnShellContext;
mnShellPop.LoadMenu(IDR_TEST_MENU);
mnShellContext=mnShellPop.GetSubMenu(0);
if (!m_bAutoStart)
{
mnShellContext->CheckMenuItem(ID_SLCCEX_AUTORUN, MF_UNCHECKED | MF_BYCOMMAND);
}
else
{
mnShellContext->CheckMenuItem(ID_SLCCEX_AUTORUN, MF_CHECKED | MF_BYCOMMAND);
}
只要通过ClassWizard给该菜单项添加以下两个消息处理函数即可1.COMMAND消息处理函数
CMainFrame::OnMenuToolBar()
{
//m_ToolBar就是你程序中的工具条对象
m_ToolBar.ShowWindow((m_ToolBar.GetStyle() & WS_VISIBLE) == 0);
}2. UPDATE_COMMAND_UI消息处理函数
CMainFrame::OnUpdateMenuToolBar(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck((m_ToolBar.GetStyle() & WS_VISIBLE) != 0);
}
然后再函数里用pCmdUI->SetCheck(bShow);bShow=!bShow;
UINT CheckMenuItem( UINT nIDCheckItem, UINT nCheck );吧
xwsn007() 的方法里面m_ToolBar是BOOL量吗?在什么地方定义,怎么和对象关联在一起?hblsf(枣) 的方法里WM_COMMAND_UI消息在哪里添加?我的类向导里对于菜单ID怎么只有COMMAND和UPDATE_COMMAND_UI这两个项呀jemmylau(枕头) 的方法我不知道加到哪个函数里。m_pMenu 在什么地方定义?还有,上面几位大虾赐教的方法好象还不太一样,小妹愈加迷惑HOHO,帮人帮到底,MM自知愚钝,大虾们写详细点呀。泣血中