Link to home
Start Free TrialLog in
Avatar of rizsid
rizsid

asked on

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.
Avatar of naveenkohli
naveenkohli

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);
}
Avatar of rizsid

ASKER

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.
oops :))
Do it in your view class..

CMyView1::OnInitialUpdate ()
{
CView::OnInitialUpdate ();
CString strDocument = GetDocument ()->GetTitle ();
CString strFrame = "My title - " + strDocument;
GetParentFrame ()->SetWindowText (strFrame);
}
Avatar of rizsid

ASKER

I also tried it in view class, in OnInitialUpdate() as u told, but it still don't work.
ASKER CERTIFIED SOLUTION
Avatar of VCGuru
VCGuru

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rizsid

ASKER

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

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

Avatar of rizsid

ASKER

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
Experts-exchange is always there for you. There are better(much better) experts than me here. Anyway I'll send u a mail
Avatar of rizsid

ASKER

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