Click to See Complete Forum and Search --> : Changing Window Name


Dallex
June 26th, 1999, 07:28 AM
I have a MDI app with a few form views derived all using
the same
ChildFrm class. The title on each child window frame is
Window1:1,
Window1:2 .......
How do I name each window in MFC.

Karl
June 28th, 1999, 08:11 AM
Override CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle)

For example:



void CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
{
CMyDoc *pDoc = (CMyDoc *)GetActiveDocument();
CMyView *pView = (CMyView *)GetActiveView();

if (bAddToTitle && pDoc){
CString strCurCaption, strWindowText, strNewCaption, strModule;
strModule = pDoc->GetModuleName(); // Get the module name
}else
strModule.LoadString(IDS_DEFAULT_TITLE);
strNewCaption += strModule;
strNewCaption += " : ";

// Get the current child window caption text
GetWindowText(strCurCaption);
// Get the special view name through the view's window text
GetActiveView()->GetWindowText(strWindowText);
// Get the doc name attached to this window
CString strPathName = pDoc->GetPathName();
if (strPathName.IsEmpty())
strNewCaption += pDoc->GetTitle();
else
strNewCaption += strPathName;
// generate our new window caption
if(!strWindowText.IsEmpty()){
strNewCaption += " - ";
strNewCaption += strWindowText;
}
if(pDoc->IsModified())
strNewCaption += "*";
// Only switch to the new caption if it differs from the old
// (this reduces flicker--MFC uses AfxSetCaption)
if (strNewCaption != strCurCaption)
SetWindowText(strNewCaption);

}
// give the MDI frame window a chance to update its title
GetMDIFrame()->OnUpdateFrameTitle(bAddToTitle);
}





HTH

K.

Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.