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

    Question How to change the title of CMDIFrameWnd when child is maximized ?

    Hi,

    As all you know, usually the title bar will show " AppTitle - [DocTitle] " . In my project, I want to
    change it to "[DocTitle] - AppTitle".

    I know the FWS_ADDTOTITLE and FWS_PREFIXTITLE settings. However, It only works when the MDI child is not maximized. When MDI child is maximized, the title
    will restore to " AppTitle - [DocTitle] " format.

    I also googled for the answer but do not find one.

    I hope someone here knows how to solve it.

    Thanks in advance

    Jeff


  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396
    Hi!
    I 've never tested this code in MDI, however in Dialog App it works fine (I use this code in InitInstance):
    Code:
    	//	change the AppName
    	//First free the string allocated by MFC at CWinApp startup.
    	//The string is allocated before InitInstance is called.
    	free((void*)m_pszAppName);
    	//Change the name of the application file.
    	//The CWinApp destructor will free the memory.
    	m_pszAppName=_tcsdup(_T("New_App_Title"));
    Try to set you title this way in form " AppTitle - [DocTitle] " and don't forget to remove standard Doc name addition to the title.

    PS:
    It is not my own code and I don't remember where I have found it

  3. #3
    Join Date
    Apr 2004
    Posts
    12
    Sorry. But I think your code can just change the word of the Title. My question is how to change the ordering from "AppTitle - [DocTitle]" to "[DocTitle] - AppTitle". when the MDI child frame is maximized.

    Actually I can not find when and where the MainFrame's title is set. I find after I SetWindowText of a ChildFrame's title, the MainFrame's title is changed to "AppTitle - [DocTitle]" format. But I can not find out which part of the code causes the change from the MFC source code.


    Originally posted by VictorN
    Hi!
    I 've never tested this code in MDI, however in Dialog App it works fine (I use this code in InitInstance):
    Code:
    	//	change the AppName
    	//First free the string allocated by MFC at CWinApp startup.
    	//The string is allocated before InitInstance is called.
    	free((void*)m_pszAppName);
    	//Change the name of the application file.
    	//The CWinApp destructor will free the memory.
    	m_pszAppName=_tcsdup(_T("New_App_Title"));
    Try to set you title this way in form " AppTitle - [DocTitle] " and don't forget to remove standard Doc name addition to the title.

    PS:
    It is not my own code and I don't remember where I have found it
    Last edited by jeffchen; April 2nd, 2004 at 09:23 PM.

  4. #4
    Join Date
    Apr 2004
    Posts
    13
    You can change your title by SetWindowText or override CMDIChildWnd::OnUpdateFrameTitle. The title is change in the fuction.

  5. #5
    Join Date
    Apr 2004
    Posts
    12
    Thanks for your reply t2di4u. But it does not work.

    Using SetWindowText on CMainFrame only change the AppTitle part and override CMDIChildWnd::OnUpdateFrameTitle can only change the DocTitle part. What I am looking for is to change the ordering of AppTitle - [DocTitle] to [DocTitle] - AppTitle, not the actual words of them.

    Originally posted by t2di4u
    You can change your title by SetWindowText or override CMDIChildWnd::OnUpdateFrameTitle. The title is change in the fuction.

  6. #6
    Join Date
    Apr 2004
    Posts
    13
    try to copy the following code to your overrided CMDIChildWnd::OnUpdateFrameTitle(BOOL bAddToTitle) fuction.

    GetMDIFrame()->OnUpdateFrameTitle(bAddToTitle);

    if ((GetStyle() & FWS_ADDTOTITLE) == 0)
    return; // leave child window alone!

    CDocument* pDocument = GetActiveDocument();
    if (bAddToTitle)
    {
    TCHAR szText[256+_MAX_PATH];
    CString strTitle;

    strTitle.LoadString(IDR_MAINFRAME);

    if (pDocument == NULL)
    lstrcpy(szText, m_strTitle);
    else
    lstrcpy(szText, pDocument->GetTitle());
    if (m_nWindow > 0)
    wsprintf(szText + lstrlen(szText), _T(":%d"), m_nWindow);

    // set title if changed, but don't remove completely
    lstrcat(szText, " - ");
    lstrcat(szText, (char *)((LPCTSTR) strTitle));
    AfxGetMainWnd()->SetWindowText(szText);
    }
    Last edited by t2di4u; April 3rd, 2004 at 06:28 AM.

  7. #7
    Join Date
    Apr 2004
    Posts
    12
    Thanks t2di4u,

    I think the codes are from MFC source code. It only works when the MDI window is not maximized. When MDI window is maximized the title of CMainFrame will return to "AppTitle - [DocTitle] " ordering.

    Have you tried the code with MDI window maximized ?
    Last edited by jeffchen; April 3rd, 2004 at 06:59 AM.

  8. #8
    Join Date
    Apr 2004
    Posts
    13
    sorry , I forgot to tell you that you should get rid of the main frame's OnUpdateFrameTitle.
    endless song

  9. #9
    Join Date
    Apr 2004
    Posts
    12
    Thanks. It works ! But there is still a problem. If use your codes in my program, the CChildFrame will not have a title. I think what your code does is to make the CChildFrame's title to NULL and set the CMainFrame's title to required text. Except this problem, it works fine.


    Originally posted by t2di4u
    sorry , I forgot to tell you that you should get rid of the main frame's OnUpdateFrameTitle.

  10. #10
    Join Date
    Apr 2004
    Posts
    13
    put this code to your child frame's OnUpdateFrameTitle

    GetMDIFrame()->OnUpdateFrameTitle(bAddToTitle);

    if ((GetStyle() & FWS_ADDTOTITLE) == 0)
    return; // leave child window alone!

    CDocument* pDocument = GetActiveDocument();
    if (bAddToTitle)
    {
    TCHAR szText[256+_MAX_PATH];
    CString strTitle;

    strTitle.LoadString(IDR_MAINFRAME);

    if (pDocument == NULL)
    lstrcpy(szText, m_strTitle);
    else
    lstrcpy(szText, pDocument->GetTitle());
    if (m_nWindow > 0)
    wsprintf(szText + lstrlen(szText), _T(":%d"), m_nWindow);

    // set title if changed, but don't remove completely
    SetWindowText(szText);
    lstrcat(szText, " - ");
    lstrcat(szText, (char *)((LPCTSTR) strTitle));
    AfxGetMainWnd()->SetWindowText(szText);
    }

    hope all goes fine.
    endless song

  11. #11
    Join Date
    Apr 2004
    Posts
    12
    Thanks. But with above code, the old problem will come back again. When the CChildFrame is maximized its title will be appended to the MainFrame. Then the MainFrame's title will be "DocTitle - AppTitle - [DocTitle]" . You will know what I mean if you try to execute the code.

  12. #12
    Join Date
    Apr 2004
    Posts
    13
    o, : (
    endless song

  13. #13
    Join Date
    May 2004
    Posts
    1
    When the MDI child is maximized the title is set by CMainFrame so you have to override the same function in your CMainFrame class too :-)

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