Solved

A CView as a child of CMDIChildWnd

Posted on 2000-05-15
7
517 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
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 6 70
modThree challenge 4 99
tripleUp challenge 7 86
How to convert MFC::CString to UTF8 wchar_t* 10 292
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 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