Solved

Setting window text of MDI MainFrame

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

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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 30

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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…
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

21 Experts available now in Live!

Get 1:1 Help Now