Solved

Setting window text of MDI MainFrame

Posted on 2000-04-06
11
1,081 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate files macro - Errors on larger data set 18 73
Expand macro to ask for filename column 8 37
maxBlock challenge 30 142
unix example issues 18 98
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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