CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    76

    Changing Window Name

    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.




  2. #2
    Join Date
    May 1999
    Location
    Toulouse, France
    Posts
    171

    Re: Changing Window Name

    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.
    We're talking ****, 'cause life is a 'biz
    You know it is
    Everybody tryin' to get rich
    God ****!
    All I wanna do is live !

    KoRn, Children of the Korn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured