Search code examples
mfcmdiwin32gui

How to show and hide the titlebar on the fly of an MDI frame?


I've been looking around and I've not been able to find any solutions that work.

I've tried to use all of these without success:

GetMDIFrame()->ModifyStyle(WS_CAPTION, 0);
GetMDIFrame()->ModifyStyle(WS_CAPTION, 0, SWP_DRAWFRAME|SWP_FRAMECHANGED);
SetWindowLong(hwnd, GWL_STYLE, ::GetWindowLong(hwnd, GWL_STYLE) & ~(WS_BORDER | WS_DLGFRAME | WS_THICKFRAME));
SetWindowLong(hwnd, GWL_EXSTYLE, ::GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_DLGMODALFRAME)

Does anyone know how to get rid of the MDI frame's titlebar? No text or bar (this includes not having the minimize, maximize and close buttons), just a thick border to be able to resize it.

I also happen to be using BCG ribbons as apparently that makes a difference in how it is rendered.


Solution

  • My answer is only valid if you use the MFC Ribbon Bar implementation or the BCG implementation. The major reason why the style flags do'nt effect a ribbon bar implementation is that the ribbon bar draws its own NC area. There is in fact no "Window caption".

    You need to initialize your CMFCRibbonBar with the bReplaceFrameCaption set to FALSE.

    CMainFrame::CMainFrame()
         : m_wndRibbonBar(FALSE)
    {
    

    Overwrite CMainFrame:PreCreateWindow and set the styles you want.

    BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
      if( !CBCGPMDIFrameWnd::PreCreateWindow(cs) )
        return FALSE;
    
      cs.style = WS_POPUPWINDOW;
    
      return TRUE;
    }
    

    This results in the effect you want enter image description here