-
April 2nd, 2004, 09:23 AM
#1
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
-
April 2nd, 2004, 09:54 AM
#2
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
-
April 2nd, 2004, 09:17 PM
#3
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.
-
April 2nd, 2004, 10:53 PM
#4
You can change your title by SetWindowText or override CMDIChildWnd::OnUpdateFrameTitle. The title is change in the fuction.
-
April 3rd, 2004, 01:01 AM
#5
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.
-
April 3rd, 2004, 06:11 AM
#6
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.
-
April 3rd, 2004, 06:57 AM
#7
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.
-
April 3rd, 2004, 08:34 AM
#8
sorry , I forgot to tell you that you should get rid of the main frame's OnUpdateFrameTitle.
endless song
-
April 3rd, 2004, 09:40 AM
#9
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.
-
April 3rd, 2004, 10:34 AM
#10
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
-
April 3rd, 2004, 11:26 AM
#11
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.
-
April 3rd, 2004, 08:30 PM
#12
-
May 15th, 2004, 04:33 AM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|