Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC: Use same menu for mainframe and childframe

MFC: Use same menu for mainframe and childframe

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wim Jans
    wrote on last edited by
    #1

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

    I 1 Reply Last reply
    0
    • W Wim Jans

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

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      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.

      W 1 Reply Last reply
      0
      • I Iain Clarke Warrior Programmer

        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.

        W Offline
        W Offline
        Wim Jans
        wrote on last edited by
        #3

        Cool, works great Thanks Iain! Wim

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups