MFC: Use same menu for mainframe and childframe
-
Hello, I'm having a bit of a problem using the same menu for my mainframe and childframe. Basically I don't need the menu that comes with the childframe. In my mainframe menu, I'm dynamically building one menu entry, and I don't want to do this processing for every child window I open, that's why I want to use the mainframe menu for the childmenu. Is there a way to prevent loading of the childframe menu? I tried to load the mainframe menu in the OnCreate Handler of my childframe, but that doesn't seem to work:
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1) return -1; CMDIFrameWnd* frame=(CMDIFrameWnd*)AfxGetMainWnd(); CMainFrame* mfrm; mfrm=(CMainFrame*)frame; CMenu NewMenu; NewMenu.m_hMenu=mfrm->m_hMenuDefault; ASSERT(NewMenu); SetMenu(NULL); ::DestroyMenu(m_hMenuDefault); SetMenu(&NewMenu); m_hMenuDefault = NewMenu; return 0; }
-
Hello, I'm having a bit of a problem using the same menu for my mainframe and childframe. Basically I don't need the menu that comes with the childframe. In my mainframe menu, I'm dynamically building one menu entry, and I don't want to do this processing for every child window I open, that's why I want to use the mainframe menu for the childmenu. Is there a way to prevent loading of the childframe menu? I tried to load the mainframe menu in the OnCreate Handler of my childframe, but that doesn't seem to work:
int CChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1) return -1; CMDIFrameWnd* frame=(CMDIFrameWnd*)AfxGetMainWnd(); CMainFrame* mfrm; mfrm=(CMainFrame*)frame; CMenu NewMenu; NewMenu.m_hMenu=mfrm->m_hMenuDefault; ASSERT(NewMenu); SetMenu(NULL); ::DestroyMenu(m_hMenuDefault); SetMenu(&NewMenu); m_hMenuDefault = NewMenu; return 0; }
Just do what I do - remove the second menu from the project entirely. When MFC tries to swap menus, it fails, and gives up with a TRACE complaint. But my first menu is untouched. You just have to make sure it has all the menu options you'll want on it, as you won't be swapping depending on situation. Iain.
-
Just do what I do - remove the second menu from the project entirely. When MFC tries to swap menus, it fails, and gives up with a TRACE complaint. But my first menu is untouched. You just have to make sure it has all the menu options you'll want on it, as you won't be swapping depending on situation. Iain.