我们知道隐藏菜单可用CMainFrame::SetMenu(NULL);来实现,但问题是在多文档情况下(MDI),第一次我可在CMyApp::InitInstance()
{
...
pMainFrame->SetMenu(NULL);
}
实现,但一旦我打开新的文档,就又出现菜单了,如何才能隐藏掉呀?

解决方案 »

  1.   

    Sorry,
    U can use this function instead
    CMenu::DestroyMenu 
    if u don't need it.
      

  2.   

    我用DestroyMenu没有成功
    (包括参考了好几个帖子:
    http://community.csdn.net/Expert/topic/3444/3444701.xml?temp=.9071924
    http://community.csdn.net/Expert/topic/3655/3655346.xml?temp=5.077541E-03

    下面是我用RemoveMenu实现的隐藏
    CMyApp::InitInstance()
    {
               .....
             const int nItems = 5; //默认因为有5个popup menu
    for(int i= nItems-1;i>=0;--i)
       pMainFrame->GetMenu()->RemoveMenu(i-1,MF_BYPOSITION);

    //pMainFrame->SetMenu(NULL);
    pMainFrame->ShowWindow(m_nCmdShow);
    pMainFrame->UpdateWindow();
    return TRUE;
    }//////////////////////////
    缺点:此时新建文档时可以隐藏MENU,
    但新建后关闭所有文档时有主框架的MENU。
      

  3.   

    手误:
    pMainFrame->GetMenu()->RemoveMenu(i-1,MF_BYPOSITION);
    应该是
    pMainFrame->GetMenu()->RemoveMenu(i,MF_BYPOSITION);
      

  4.   

    I_Love_CPP(我爱C++) ,谢谢您的热心参与,我试了您的方法,是有效,但有bug,当View窗口最大化时,还是会出现menubar
      

  5.   

    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    if( !CFrameWnd::PreCreateWindow(cs) )
    return FALSE;
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs
    cs.hMenu = NULL;// 隐藏菜单 return TRUE;
    }