Remove the document title text from the main window only

Flaviu_ 971 Reputation points
2022-03-13T11:57:35.683+00:00

I have a MDI app. It is possible to remove the document title text from the main window title only ?

182448-untitled.png

I have tried to use:

cs.style &= ~FWS_ADDTOTITLE;  

in PreCreateWindow

in child frame and / or in main frame, not worked. I have tried to overload OnUpdateFrameTitle, the same in child frame and or in mainframe. Not worked.

void CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle)  
{  
// CMDIChildWndEx::OnUpdateFrameTitle(bAddToTitle);  
  
 CString csAppName;  
 csAppName.Format(AFX_IDS_APP_TITLE);  
 Set caption of main frame window  
 //---------------------------------  
 SetWindowText(csAppName);  
// SetWindowText(GetActiveDocument()->GetTitle());  
}  
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,636 questions
{count} votes

Accepted answer
  1. RLWA32 43,306 Reputation points
    2022-03-13T18:35:04.223+00:00

    When the MDI child window is maximized the caption (document title) is drawn by DefMDIChildProc.

    In addition to the above override to CMainFrame::OnUpdateFrameTitle add a handler to the CChildFrame class to handle WM_CHILDACTIVATE -

    void CChildFrame::OnChildActivate()
    {
        CMDIChildWndEx::OnChildActivate();
    
        if (IsZoomed())
            SetWindowText(_T(""));
        else
            CMDIChildWndEx::OnUpdateFrameTitle(TRUE);
    }
    

    I haven't tested for all possibilities. One side effect of the above is that when the title of the MDI child is removed it is also removed from the Window menu.

    I don't quite understand the purpose of removing the document title when the MDI child is maximized. If more than one MDI child window is open it obscures the identity of the window in which the user is working.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Guido Franzke 2,196 Reputation points
    2022-03-15T06:55:28.247+00:00

    Hello,
    in MDI you can set the title of the child frames in CDocument's OnNewDocument and OnOpenDocument with SetTitle:

    BOOL CMyDoc::OnNewDocument()
    {
        if (!CDocument::OnNewDocument())
            return FALSE;
    
        SetTitle(::AfxGetAppName());
    
        return TRUE;
    }
    

    Regards, Guido

    1 person found this answer helpful.
    0 comments No comments

  2. RLWA32 43,306 Reputation points
    2022-03-13T12:19:39.427+00:00

    Try this -

    void CMainFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
    {
        // TODO: Add your specialized code here and/or call the base class
    
        CMDIFrameWndEx::OnUpdateFrameTitle(FALSE);
    }