locked
MFC support for auto hiding menus

    Question

  • MFC 9.0 has support for the automaticall and manual hiding of menus. To enable that, SetMenuBarVisibility must be called. This method of class CFrameWnd requires AFX_MBV_DISPLAYONFOCUS to be passed in order to hide the menu automatically and show it only when pressing the ALT key.

     

    However, this only works in SDI applications. In an MDI application calling that for the child frame (derived from CMDIChildWnd) does not have any effect. Trying to call the method with any other parameter than AFX_MBV_KEEPVISIBLE results in an assertion failure, because the mothod is overriden in CMDIFrameWnd:

    Code Snippet

    void CMDIFrameWnd::SetMenuBarVisibility(DWORD dwStyle)
    {
       ENSURE_ARG
    (dwStyle == AFX_MBV_KEEPVISIBLE);
       ASSERT
    (m_dwMenuBarVisibility == AFX_MBV_KEEPVISIBLE);
    }

     

    Why is this not working for MDI apps, and why is this not explained either in the VC++ blog (http://blogs.msdn.com/vcblog/archive/2007/03/21/mfc-updates-for-vista-common-controls.aspx) or the MSDN Magazine (http://msdn.microsoft.com/msdnmag/issues/07/06/Cpp/)?

     

    Thank you.

    Monday, July 09, 2007 1:15 PM

Answers

  • Hello Marius,

    This feature was designed to not support hiding of menus in MDI applications. One of the reasons for this decision was that it was unclear what should be happening with minimize/restore/close buttons on menu bar associated with the child window. Also most of the MDI apps have  complex menus and Vista UX guidelines do not encourage hiding complex menu bars.

     

    Thanks

    Sarita Bafna

    Visual C++ Team

     

     

    Monday, July 09, 2007 7:36 PM