Solved

A CView as a child of CMDIChildWnd

Posted on 2000-05-15
7
525 Views
Last Modified: 2013-11-20
I have a MDI child and CView, but in CMDIChild I have some toolbars as well. How can I do this: my CView shouldn't take all the client area (except toolbars) in CMDIChildWnd, and between CView and CMDIChild should be left 5 pixels in each side for example. Is it can be done by overloading some functions in CMDIChild or CView?
I tried this:
void CContainerView::OnSize(UINT nType, int cx, int cy)
{
      CView::OnSize(nType, cx-10, cy-10);
      CRect rct;
      GetParent()->GetClientRect(&rct);
      MoveWindow(5,5,rct.right-10,rct.bottom-10);
}
But it isn't take in account toolbars.
Important: toolbars are OLE server toolbars created by another application, and I don't know how many space they use.
0
Comment
Question by:double_axe
[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
  • 2
7 Comments
 
LVL 3

Author Comment

by:double_axe
ID: 2813088
You may help, if just answer, how to change client rect of window dynamically, so that GetClientRect return this rect.
0
 
LVL 3

Author Comment

by:double_axe
ID: 2813110
You may help, if just answer, how to change client rect of window dynamically, so that GetClientRect return this rect.
0
 
LVL 12

Expert Comment

by:migel
ID: 2813285
Hi!
Try CMdiChildWnd::RecalcLayout(BOOL bNotify)

for example:
CMyMDIChildWnd::OnSize(...)
{
CMDIChildWnd::OnSize();
RecalcLayout(FALSE);
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:double_axe
ID: 2815890
No, my example doesn't work 'cause GetParent()->GetClientRect(&rct); returns all the client rect, uncluding toolbars. I solved this problem by myself this way:

void CMyView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
{
      CView::CalcWindowRect(lpClientRect, nAdjustType);

            lpClientRect->right-=5;
            lpClientRect->bottom-=5;
            lpClientRect->top+=5;
            lpClientRect->left+=5;
}

But I can give you some pts, 'cause I can't get them back;))
0
 
LVL 12

Accepted Solution

by:
migel earned 50 total points
ID: 2816051
hmm
In generaly MFC archeticture assume that child window must be resized by parent, not itself, so did you try my reccomendation (and remove CContainerView::OnSize(UINT nType, int cx, int cy) )?
0
 
LVL 3

Author Comment

by:double_axe
ID: 2816473
But that one workes pretty fine. And from within CMyMDIChildWnd::OnSize() it's possible too, but there will be more code (need to get size of CView, then substract some pixels from this size, and call MoveWindow to set new size, and only after this call RecalcLayout to arrange toolbars and CView).
0
 
LVL 3

Author Comment

by:double_axe
ID: 2840538
Hi migel. You were right:)). My method worked fine, when CView was a child of CMDIChild, but when I inserted it into CSplitterWnd, I didn't get any results. I tried some methods, but only one worked fine. Guess what?:))) I had to reimplement CSplitterWnd::RecalcLayout() as follows:
void CViewExSplitWnd::RecalcLayout()
{
      CSplitterWnd::RecalcLayout();
         CFrameWnd *pFrame=GetParentFrame();
         if(!pFrame)
               return;

         CView *pView=pFrame->GetActiveView();
         if(!pView)
               return;

         if(((CChildFrame *)pFrame)->m_bColoredFrame)
         {
               RECT rct;
               pView->GetWindowRect(&rct);
               pView->GetParent()->ScreenToClient(&rct);
               pView->MoveWindow(rct.left+ALERT_BORDER_SIZE,rct.top+ALERT_BORDER_SIZE,
                     rct.right-rct.left-2*ALERT_BORDER_SIZE,rct.bottom-rct.top-2*ALERT_BORDER_SIZE);
               pFrame->RedrawWindow();
         }
}

Generally you were right, parent must resize it's children. So, I'll accept your answer.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

751 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