Solved

Setting window text of MDI MainFrame

Posted on 2000-04-06
11
1,057 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sum13 challenge 24 90
ShiftLeft challenge 21 76
Line meaning 9 82
Way to decrease size of apk file 9 45
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now