Vista Aero’s Menus Hiding with MFC 9.0

You probably noticed that IE7 or Windows Media Player 11 don’t have the menu shown by default; it only shows up when you press the ALT key. This is one particularity of the look and feel of Windows Vista Aero. You can find guidelines about designing menus here:

As revealed by the VC++ team some time ago, MFC 9.0 offers support for hiding the menus automatically and manually, in accordance with the Aero look and feel. A recent article in the MSDN Magazine by Tarek Madkour, explains how: by calling the SetMenuBarVisibility method from CFrameWnd with the AFX_MBV_DISPLAYONFOCUS. What is not told is that works only for SDI applications.

Menus in SDI applications 

In a SDI application you have a class derived from CFrameWnd, usually called CMainFrame. In the OnCreate() method, after calling CFrameWnd::OnCreate, you can call SetMenuBarVisibility:

AFX_MBV_DISPLAYONFOCUS is defined in afxwin.h:

The result is that the menu is automatically hidden (as can be seen in the image)

SDI menu is hidden 

and shown only when pressing the ALT key.

SDI menu is shown

Menus in MDI applications

The same technique does not work for MDI menus. In such an application you have

  • a main frame, represented by a (usually called) CMainFrame class derived from CMDIFrameWnd, which in turn is derived from CFrameWnd, and
  • one or more child frames, derived from CMDIChildFrame, which in turn is derived from CFrameWnd

Both the main window and the child windows can have menus, but the menu of a child window is shown on the same bar with the menu of the main window. As long as a child window exists the menu of that document is shown. When no child window exists the menu of the main window is shown. Both on the same bar.

Trying to make the menu of the child window(s) hidden by default does not work. Calling SetMenuBarVisibility has no effect:

Calling SetMenuBarVisibility for the main frame results in an assertion failure because the implementation in the CMDIFrameWnd expects the parameter to be always AFX_MBV_KEEPALIVE; it doesn’t do anything else, such as calling the function from the base class.

Overriding the method in CMainFrame accept any parameter and call the method in CFrameWnd to bypass CMDIFrameWnd does not have any effect either.

In conclusion MFC 9.0 supports the Aero look-and-feel for the automatically hiding of menus, but only in SDI applications.

3 Replies to “Vista Aero’s Menus Hiding with MFC 9.0”

  1. It seems to be possible to hide the menubar of the MDI main frame too, by calling SetMenuBarState(AFX_MBS_HIDDEN)

  2. short update to above comment. When pressing Ctrl-N a new MDI document is opened and the menu reappears. Calling SetMenuBarState(AFX_MBS_HIDDEN) doesn’t seem to help here to hide it again.

    I managed to get rid of the menu by deleting all items contained in it:

    Menu* mainFrameMenu = pMainFrame->GetMenu();
    if (::IsMenu(mainFrameMenu->m_hMenu)) {
    int count = mainFrameMenu->GetMenuItemCount();
    while (count >0){
    mainFrameMenu->DeleteMenu(0,MF_BYPOSITION);
    count = mainFrameMenu->GetMenuItemCount();
    }
    }

    pMainFrame is the MDI main frame window created by Visual Studio wizard.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.