Solved

Setting window text of MDI MainFrame

Posted on 2000-04-06
11
1,069 Views
Last Modified: 2013-11-20
How can I set the title bar text other than it being got from the IDR_MAINFRAME resource?

Cheers
0
Comment
Question by:TSMITH
  • 3
  • 2
  • 2
  • +3
11 Comments
 
LVL 1

Expert Comment

by:MFCAnswer
ID: 2690896
AfxGetMainWindow()->SetWindowText("title");

if u want to change it permanantly then override on new document function
and set the title there so that every time when new doc is opened ur mainframe window caption is not changed.

another option is to change the CREATESTRUCT structur in precreate window to change the parameter lpszName

eg:
cs.lpszName = "New title";

hope it helps

0
 

Expert Comment

by:sunraj
ID: 2692417
hi smith,

The following will change the title from anywhere from the MFC code,

The application object is having a pointer to mainframe window viz m_pMainWnd.

First u obtain the pointer to your application,

CMyApp *hello = (CMyApp*)AfxGetApp();
hello->m_pMainWnd->SetWindowText();

Pass on the title string to SetWindowText();
0
 

Expert Comment

by:sunraj
ID: 2692420
hi smith,

The following will change the title from anywhere from the MFC code,

The application object is having a pointer to mainframe window viz m_pMainWnd.

First u obtain the pointer to your application,

CMyApp *hello = (CMyApp*)AfxGetApp();
hello->m_pMainWnd->SetWindowText();

Pass on the title string to SetWindowText();

If u feel difficult, make a comment.
But the above will work
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Expert Comment

by:sunraj
ID: 2692425
hi smith,

The following will change the title from anywhere from the MFC code,

The application object is having a pointer to mainframe window viz m_pMainWnd.

First u obtain the pointer to your application,

CMyApp *hello = (CMyApp*)AfxGetApp();
hello->m_pMainWnd->SetWindowText();

Pass on the title string to SetWindowText();

If u feel difficult, make a comment.
But the above will work
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2692589
Hi TSMITH,

if you don't want the current document's filename to appear in the title remove the FWS_ADDTOTITLE style in CMainFrame::PreCreateWindow().

ZOPPO
0
 

Author Comment

by:TSMITH
ID: 2692659
I'm using an MDI application, none of the above suggestions work.

The window text is always obtained from the IDR_MAINFRAME resource, I need to alter the title dynamically.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2692682
Hi TSMITH,

working code:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  return -1;

 SetWindowText( "My Application..." );
 ...
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
 cs.style &= ~FWS_ADDTOTITLE;
 return CMDIFrameWnd::PreCreateWindow(cs);
}

hope that helps,

ZOPPO
0
 
LVL 1

Accepted Solution

by:
elston_sa earned 50 total points
ID: 2692784
Just Add the followoing function in your mainframe class,

void CMainFrame::SetTitle(CString newtitle)
{
    m_strTitle = newtitle;
}

Call it wherever required

0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2696383
See the documentation for CDocument::SetTitle(LPCTSTR lpszTitle)
0
 
LVL 1

Expert Comment

by:elston_sa
ID: 2699043
This function

CDocument::SetTitle(LPCTSTR lpszTitle)

is used to specify the document’s title. Not the Mainframe window title loaded from the resources.

Actually the following is My function to set the Mainframe title,

void CMainFrame::SetMyTitle(CString newtitle)
{
    m_strTitle = newtitle;
}
0
 
LVL 3

Expert Comment

by:SamHobbs
ID: 2699374
Yes, you are correct, elston_sa, CDocument::SetTitle will not change the portion of the title bar text that is obtained from the IDR_MAINFRAME resource if it is there (the application name).

However, depending on requirements, another possibility is to set the application name in the CWinApp derived class's constructor.

0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question