在VC里用MDI风格,做菜单的时候想做一个控制两种状态转换的菜单选项,点一下置位,再点一下复位,再点又置位就这么反复。就象WORD里的“工具栏”、“菜单栏”选项一样,点一下工具栏出来,再点一下工具栏消失,再点又出来大家快帮帮忙呀,我都要哭死了。

解决方案 »

  1.   

    //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);
    }
      

  2.   

    别急,其实不麻烦的
    只要通过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);
    }
      

  3.   

    给菜单项的ID加上WM_COMMAND_UI消息
    然后再函数里用pCmdUI->SetCheck(bShow);bShow=!bShow;
      

  4.   

    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. 
      

  5.   


    UINT CheckMenuItem( UINT nIDCheckItem, UINT nCheck );吧
      

  6.   

    感谢各位大虾抬爱有加,回复了这么多帖子。但是。。很不幸,小妹实在菜了点,到现在还没弄出来的说。kingzai(studying C#)的方法里面ID_SLCCEX_AUTORUN这个编译的时候出错,说什么不认识。
     xwsn007() 的方法里面m_ToolBar是BOOL量吗?在什么地方定义,怎么和对象关联在一起?hblsf(枣) 的方法里WM_COMMAND_UI消息在哪里添加?我的类向导里对于菜单ID怎么只有COMMAND和UPDATE_COMMAND_UI这两个项呀jemmylau(枕头) 的方法我不知道加到哪个函数里。m_pMenu 在什么地方定义?还有,上面几位大虾赐教的方法好象还不太一样,小妹愈加迷惑HOHO,帮人帮到底,MM自知愚钝,大虾们写详细点呀。泣血中