?
Solved

Setting of Title of an MDI Child Window

Posted on 1999-06-29
11
Medium Priority
?
481 Views
Last Modified: 2013-11-20
I have developed an MDI applicatoins containging about 25 child windows. Each child window is selected through menu and deals different tasks. The problem is how to set the deffernt Title (Caption) of each child window.
0
Comment
Question by:rizsid
[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
  • 5
  • 4
  • 2
11 Comments
 
LVL 23

Expert Comment

by:naveenkohli
ID: 1308349
You can override the OnUpdateFrameTitle in your child frame classes and set the title the way you want to.

Here is sample code from one of my drawing application. This has been done for SDI but works for MDI also cause this function is member of CFrameWnd. With this function you can update the title everytime its saved.

virtual void OnUpdateFrameTitle(BOOL bAddToTitle);

void CMainFrame::OnUpdateFrameTitle (BOOL bAddToTitle)
{
      // If you want to add the Untitled to the title , then set the argument for
      // base class call to TRUE.

      CFrameWnd::OnUpdateFrameTitle (FALSE);

      CString strInitial (_T (""));
      GetWindowText (strInitial);

      // Create the new title

      CString strNewTitle = _T ("< Drawing View - ") + strInitial + _T (" >");
      SetWindowText (strNewTitle);
}
0
 

Author Comment

by:rizsid
ID: 1308350
I implemented the function as u told. But it sets the title of the MainFrame window not the child window. I want to set different titles for different child windows.
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 1308351
oops :))
Do it in your view class..

CMyView1::OnInitialUpdate ()
{
CView::OnInitialUpdate ();
CString strDocument = GetDocument ()->GetTitle ();
CString strFrame = "My title - " + strDocument;
GetParentFrame ()->SetWindowText (strFrame);
}
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:rizsid
ID: 1308352
I also tried it in view class, in OnInitialUpdate() as u told, but it still don't work.
0
 
LVL 3

Accepted Solution

by:
VCGuru earned 200 total points
ID: 1308353
try this
In the
CChildFrame::PreCreateWindow(...)
{
      cs.style &=~FWS_ADDTOTITLE;
      return CMDIChildWnd::PreCreateWindow(cs);
}

In your views OnInitialUpdate(..

CMyView::OnInitialUpdate()
{
CView::OnInitialUpdate();
      
      
      CString str = GetDocument()->GetTitle();
      CString str1 = "MyOwn" + str;
      GetParentFrame()->SetWindowText(str1);
}
Hope this helps
0
 

Author Comment

by:rizsid
ID: 1308354
Dear VCGuru, You are a Genius. You have really solved my big problem. I need a little more favour. Can you also guide me for every individual child window, how to make default settings like its size and position, background color etc
0
 
LVL 3

Expert Comment

by:VCGuru
ID: 1308355
Hi rizsid,
To change the background color of each view you'll have to override the OnEraseBkgnd function for each view. Then use the follwing code

BOOL CMyView::OnEraseBkgnd(CDC* pDC)
{
      // TODO: Add your message handler code here and/or call default
      CRect rect;
      pDC->GetClipBox(&rect);

      CBrush br(RGB(0,255,0));

      CBrush *pb = pDC->SelectObject(&br);

      pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);

      pDC->SelectObject(pb);
      return 1;
      //return CView::OnEraseBkgnd(pDC);
}

Rest Later

0
 
LVL 3

Expert Comment

by:VCGuru
ID: 1308356
Hi rizsid,
To change the background color of each view you'll have to override the OnEraseBkgnd function for each view. Then use the follwing code

BOOL CMyView::OnEraseBkgnd(CDC* pDC)
{
      // TODO: Add your message handler code here and/or call default
      CRect rect;
      pDC->GetClipBox(&rect);

      CBrush br(RGB(0,255,0));

      CBrush *pb = pDC->SelectObject(&br);

      pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);

      pDC->SelectObject(pb);
      return 1;
      //return CView::OnEraseBkgnd(pDC);
}

Rest Later

0
 

Author Comment

by:rizsid
ID: 1308357
You are a real Guru. Thank you very much. I am new to VC. If do don't mind, Can u give me your email, for time to time help. My email is rsiddiqi@hotmail.com
0
 
LVL 3

Expert Comment

by:VCGuru
ID: 1308358
Experts-exchange is always there for you. There are better(much better) experts than me here. Anyway I'll send u a mail
0
 

Author Comment

by:rizsid
ID: 1308359
In from Asia (Pakistan) working in a software house. Can you guide me from where can I get the appropriate training of Visual C++.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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