Removing a menu in an SDI (MFC .Net)

juan_herbst
juan_herbst used Ask the Experts™
on
I am trying to remove a menu in a SDI application. I have done the following:

BOOL CXXXSApp::InitInstance()
{
.
.
.
.
.
        m_pMainWnd->ModifyStyle(WS_CAPTION ,SWP_SHOWWINDOW);
        m_pMainWnd->SetMenu(NULL);
}

The menu dissapears but when I call GetClientRect() from a view the size of the menu is excluded from the rect at the bottom of the view.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
MSDN Says

Steps to Create SDI Application that Has No Menu Bar
Generate an SDI application with AppWizard. Do not delete the IDR_MAINFRAME menu resource. If you have an application that was not generated with AppWizard, do not delete the corresponding main menu resource. Leaving the menu resource is required to avoid assertion failures in the MFC code.


To prevent the main application window from having a menu bar, delete the already loaded menu, and set the hMenu field of the CREATESTRUCT structure to NULL in the CFrameWnd::PreCreateWindow() function:

      BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
      {
         if(cs.hMenu!=NULL)
         {
             ::DestroyMenu(cs.hMenu);      // delete menu if loaded
             cs.hMenu = NULL;              // no menu for this window
         }

         return CFrameWnd::PreCreateWindow(cs);
      }


Good Luck

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial