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. Hide & Show Menu bar dynamically

Hide & Show Menu bar dynamically

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionhelplearning
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.
  • M Offline
    M Offline
    mclpun
    wrote on last edited by
    #1

    Hi All, I' m writing a Visual C++ MFC dialog-based program. I added a Menu bar uisng Insert->Resource-> Menu, not by writing code. Then, I tried to show and hide the Menu bar of a modal dialog dynamically. By writing the following code, I succeed to hide the menu bar. CWnd* pMain = AfxGetMainWnd(); if (pMain != NULL) { CMenu* pMenu = pMain->GetMenu(); while(pMenu != NULL && pMenu->GetMenuItemCount() > 0) { pMenu->DeleteMenu(0, MF_BYPOSITION); pMain->DrawMenuBar(); } } But how can I show the menu again? Please kindly help me! Cheers, hmc

    S 1 Reply Last reply
    0
    • M mclpun

      Hi All, I' m writing a Visual C++ MFC dialog-based program. I added a Menu bar uisng Insert->Resource-> Menu, not by writing code. Then, I tried to show and hide the Menu bar of a modal dialog dynamically. By writing the following code, I succeed to hide the menu bar. CWnd* pMain = AfxGetMainWnd(); if (pMain != NULL) { CMenu* pMenu = pMain->GetMenu(); while(pMenu != NULL && pMenu->GetMenuItemCount() > 0) { pMenu->DeleteMenu(0, MF_BYPOSITION); pMain->DrawMenuBar(); } } But how can I show the menu again? Please kindly help me! Cheers, hmc

      S Offline
      S Offline
      Serge Krynine
      wrote on last edited by
      #2

      I think this code illustrates what you need: void CShowHideMenuDlg::OnShowMenu() { // Load and add the new menu CMenu mMainMenu; mMainMenu.LoadMenu(IDR_MENU1); ASSERT(mMainMenu); SetMenu(&mMainMenu); } void CShowHideMenuDlg::OnHideMenu() { // Remove and destroy the old menu SetMenu(NULL); ::DestroyMenu(GetMenu()->GetSafeHmenu()); } Regards, Serge Krynine

      M 1 Reply Last reply
      0
      • S Serge Krynine

        I think this code illustrates what you need: void CShowHideMenuDlg::OnShowMenu() { // Load and add the new menu CMenu mMainMenu; mMainMenu.LoadMenu(IDR_MENU1); ASSERT(mMainMenu); SetMenu(&mMainMenu); } void CShowHideMenuDlg::OnHideMenu() { // Remove and destroy the old menu SetMenu(NULL); ::DestroyMenu(GetMenu()->GetSafeHmenu()); } Regards, Serge Krynine

        M Offline
        M Offline
        mclpun
        wrote on last edited by
        #3

        Thanks Serge, got it!:)

        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