Solved

A CView as a child of CMDIChildWnd

Posted on 2000-05-15
7
498 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now