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