Domanda

I always been interested on how we can accomplish this (hide/show the main menu using the alt key), and now some applications do this very often. One that really please me is the visual studio 2010 with this plugin: http://visualstudiogallery.msdn.microsoft.com/bdbcffca-32a6-4034-8e89-c31b86ad4813?SRC=VSIDE

(firefox also do this, but i think that is in a different way)

Can anyone explain me how this can be achieved or if you known of any sample project that demonstrate this please tell me.

(what i can see in some replies here in stack is that we have to destroy the menu when is to hide and create it when is to show?! but this seems a bit bad solution...)

Thanks

È stato utile?

Soluzione

The SetMenu function lets you add/remove the menu from the window. It does not destroy the menu.

Note that most applications which have the dynamic menu hide/show behavior are not really showing a menu. They're showing a custom control that looks like a menu.

Altri suggerimenti

You might also take a look at MFC support for auto hiding menus. I used this technique and it worked really well.

in CMainFrame::OnCreate I did m_wndMenuBar.ShowWindow(SW_HIDE); which actually works fine in our project

I stumbled across a related pit fall that will show a hidden main frame without your consent:

Whenever the focus for a child window in an MDI application changes (e.g. due to right clicking in it), the function CMDIChildWnd::OnMDIActivate will be called, which in turn shows the main menu (even if it was removed or destroyed previously) of the MDI application. This works basically by adding the saved main manu from the underlying's CMDIChildWnd m_hMenuShared variable.

A quick&dirty hack to prevent this, is setting m_hMenuShared to NULL (it's protected in CMDIChildWnd so this needs a custom derived child class of CMDIChildWnd) for all child frames.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top