Solved

Setting window text of MDI MainFrame

Posted on 2000-04-06
11
1,089 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Hibernate methods 2 83
NotAlone Challenge 20 88
EvenOdd challenge 10 146
Problem to App 4 119
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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