CDocument::SetTitle

Flaviu_ 911 Reputation points
2022-03-11T11:12:20.843+00:00

I have a MFC MDI app, with tabbed childs.

And I want to change the title of the document and tab, after the document is loaded. And I noticed that CDocument::SetTitle is working on OnNewDocument, but not from OnOpenDocument:

BOOL CMyDoc::OnNewDocument()  
{  
 if (! CDocument::OnNewDocument())  
 return FALSE;  
  
 // TODO: add reinitialization code here  
 // (SDI documents will reuse this document)  
  
 SetTitle(_T("AAA")); // working  
  
 return TRUE;  
}  
  
BOOL CMyDoc::OnOpenDocument(LPCTSTR lpszPathName)  
{  
 if (! CDocument::OnOpenDocument(lpszPathName))  
 return FALSE;  
  
 // TODO: Add your specialized code here and/or call the base class  
  
 SetTitle(_T("BBBB")); // not working  
  
 return TRUE;  
}  

How can I solve that ?

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,557 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. David Lowndes 4,711 Reputation points
    2022-03-11T12:10:41.58+00:00

    See if this thread helps.

    0 comments No comments

  2. Flaviu_ 911 Reputation points
    2022-03-11T14:55:12.817+00:00

    I have found a workaround: to setup the document title inside of CMyView::OnInitialUpdate:

    void CMyView::OnInitialUpdate()
    {
    CListView::OnInitialUpdate();
    
    // TODO: You may populate your ListView with items by directly accessing
    //  its list control through a call to GetListCtrl().
    
    GetDocument()->SetTitle(_T("BBBB"));
    }
    
    0 comments No comments