Solved

A CView as a child of CMDIChildWnd

Posted on 2000-05-15
7
510 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 98
Expand to include initial dialog with two choices. 9 77
sumDigits challenge 9 147
Work with App store 7 51
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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