• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 496
  • Last Modified:

Setting of Title of an MDI Child Window

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
rizsid
Asked:
rizsid
  • 5
  • 4
  • 2
1 Solution
 
naveenkohliCommented:
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
 
rizsidAuthor Commented:
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
 
naveenkohliCommented:
oops :))
Do it in your view class..

CMyView1::OnInitialUpdate ()
{
CView::OnInitialUpdate ();
CString strDocument = GetDocument ()->GetTitle ();
CString strFrame = "My title - " + strDocument;
GetParentFrame ()->SetWindowText (strFrame);
}
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
rizsidAuthor Commented:
I also tried it in view class, in OnInitialUpdate() as u told, but it still don't work.
0
 
VCGuruCommented:
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
 
rizsidAuthor Commented:
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
 
VCGuruCommented:
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
 
VCGuruCommented:
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
 
rizsidAuthor Commented:
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
 
VCGuruCommented:
Experts-exchange is always there for you. There are better(much better) experts than me here. Anyway I'll send u a mail
0
 
rizsidAuthor Commented:
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

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now