Does anyone know of a way to enable and disable the menu bar programatically. Say I want to start an application without the menu bar and after some hotkey enable the menu. I can do toolbars, they are controlbars, but not the menu bar. Thanks for any help.
If it is inside a MFC program you have to add a handler of type ON_UPDATE_COMMAND_UI for the menu item.
You will receive a pointer to a CCmdUI object to disable/enable your menu item.
I think it also exists a ON_UPDATE_COMMAND_UI_RANGE to specify a renge of cosecutive(as IDs) menu items.
If it is a SDK Application you must treat WM_INITMENUPOPUP message.
Hope this helps, s-)
Blessed is he who in the name of justice and good will, shepards the week through the valley of darkness...
Unfortunatly CMenu object isn't a window so I can't call ShowWindow on it as you normally would with a Toolbar ie. CControlBar. Also the ON_UPDATE_COMMAND only works with individual items not the whole menu itself. And I'd rather remove it rather than just greying it out.
I've implemented the following which seems to work but when you hit a hot-key (ie. Cntl->N for a new document) the menu bar comes back.
void CMainFrame::OnButtonKillmenu()
{
// Remove and destroy the old menu.
SetMenu(NULL);
CMenu* old_menu = CMenu::FromHandle(m_hMenuDefault);
old_menu->DestroyMenu();
m_hMenuDefault = NULL;
gbMenuBar = false;
}
void CMainFrame::OnButtonRestoremenu()
{
// Load the new menu.
m_NewMenu.LoadMenu(IDR_MFCTYPE);
ASSERT(m_NewMenu);
// Add the new menu
SetMenu(&m_NewMenu);
// Assign default menu
m_hMenuDefault = m_NewMenu.GetSafeHmenu(); // or m_NewMenu.m_hMenu;
DrawMenuBar();
gbMenuBar = true;
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.