Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable/Disable MenuBar

Status
Not open for further replies.

jbholtz

Programmer
Jul 29, 2001
3
US
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.

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


Thanks for the replies
 
Try to use the DeleteMenu function from the CMenu class.It will delete a menu item by its ID.
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top