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. How to dynamically modify menu in MDI app

How to dynamically modify menu in MDI app

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 3 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.
  • J Offline
    J Offline
    JerzyPeter
    wrote on last edited by
    #1

    Hello everybody! I´m writing a MDI app. Application Wizard generates two menus: One (IDR_MAINFRAME), which is displayed when no document is open, the other (IDR_XXXTYPE) when there is at least one document opened. This code below (from CMainFrame::OnCreate) modifies the first menu. I want to do the same modification to the other menu. How to do that? Thank you for any comments. Jerzy CMenu PopupMenu; PopupMenu.CreateMenu(); for(int i=0;i<3;i++) { CString str; str.Format("Item %d",i); PopupMenu.AppendMenu(MF_STRING,IDM_ITEM+i,str) ; } CMenu *m=GetMenu(); m->AppendMenu(MF_POPUP¦MF_STRING,(UINT)PopupMenu.m_hMenu,"&Items"); PopupMenu.Detach();

    N 1 Reply Last reply
    0
    • J JerzyPeter

      Hello everybody! I´m writing a MDI app. Application Wizard generates two menus: One (IDR_MAINFRAME), which is displayed when no document is open, the other (IDR_XXXTYPE) when there is at least one document opened. This code below (from CMainFrame::OnCreate) modifies the first menu. I want to do the same modification to the other menu. How to do that? Thank you for any comments. Jerzy CMenu PopupMenu; PopupMenu.CreateMenu(); for(int i=0;i<3;i++) { CString str; str.Format("Item %d",i); PopupMenu.AppendMenu(MF_STRING,IDM_ITEM+i,str) ; } CMenu *m=GetMenu(); m->AppendMenu(MF_POPUP¦MF_STRING,(UINT)PopupMenu.m_hMenu,"&Items"); PopupMenu.Detach();

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Use GetSubMenu to get the proper menu and continue as you have been.

      J 1 Reply Last reply
      0
      • N Not Active

        Use GetSubMenu to get the proper menu and continue as you have been.

        J Offline
        J Offline
        JerzyPeter
        wrote on last edited by
        #3

        Hi, I don't know what you mean to use GetSubMenu()? This code is working, it ataches a new popup to the main menu. The problem is that it ataches this submenu to the IDR_MAINFRAME menu (after main frame is created). I need to do the same for IDR_VIEWTYPE menu. I don't know in what moment that menu is created. If I use this code in that moment, the new popup would be attached to IDR_VIEWTYPE menu. Jerzy

        T 1 Reply Last reply
        0
        • J JerzyPeter

          Hi, I don't know what you mean to use GetSubMenu()? This code is working, it ataches a new popup to the main menu. The problem is that it ataches this submenu to the IDR_MAINFRAME menu (after main frame is created). I need to do the same for IDR_VIEWTYPE menu. I don't know in what moment that menu is created. If I use this code in that moment, the new popup would be attached to IDR_VIEWTYPE menu. Jerzy

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          The handle of the IDR_XXXTYPE menu is accessible through public data member of the CMultiDocTemplate class, it's called m_hMenuShared. Tomasz Sowinski -- http://www.shooltz.com

          J 1 Reply Last reply
          0
          • T Tomasz Sowinski

            The handle of the IDR_XXXTYPE menu is accessible through public data member of the CMultiDocTemplate class, it's called m_hMenuShared. Tomasz Sowinski -- http://www.shooltz.com

            J Offline
            J Offline
            JerzyPeter
            wrote on last edited by
            #5

            Hi Tomek, Thanks for the solution. It works - it ataches a new popup to IDR_XXXTYPE menu. But the problem is that I don't know where this code should be placed. If I put it in OnCrete() of ChildFrm, then the new popup is atached as many times as ChildFrm frames were created. MSDN says something that this menu is loaded during the construction of the document templates. Can I override this? Thanks for any suggestions. Jerzy

            T 1 Reply Last reply
            0
            • J JerzyPeter

              Hi Tomek, Thanks for the solution. It works - it ataches a new popup to IDR_XXXTYPE menu. But the problem is that I don't know where this code should be placed. If I put it in OnCrete() of ChildFrm, then the new popup is atached as many times as ChildFrm frames were created. MSDN says something that this menu is loaded during the construction of the document templates. Can I override this? Thanks for any suggestions. Jerzy

              T Offline
              T Offline
              Tomasz Sowinski
              wrote on last edited by
              #6

              You should add popups after creating new CMultiDocTempltate, in CYourApp::InitInstance. Tomasz Sowinski -- http://www.shooltz.com

              J 1 Reply Last reply
              0
              • T Tomasz Sowinski

                You should add popups after creating new CMultiDocTempltate, in CYourApp::InitInstance. Tomasz Sowinski -- http://www.shooltz.com

                J Offline
                J Offline
                JerzyPeter
                wrote on last edited by
                #7

                Hi Tomek, Thank you very much for this tip. It works. I had to only call DrawMenuBar() to refresh the menu. Without this call the menu was updated only when the mouse was over the menu. (This is only when the application starts). When all documents were closed and then I opened a new one the menu was shown correctly. Dziekuje, Jerzy :)

                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