Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing the Size of a MDI Child Frame Around a CFormView

Posted on 1999-07-21
31
Medium Priority
?
604 Views
Last Modified: 2013-11-20
I have an AppWizard generated MDI app.  The first view was default generated based on CFormView.  I edited the dialog-template resource to reflect what I needed.  When I run the app, everthing comes up okay.  The problem is that the window has scrollbars.  I want to display the form with now scrollbars.  I want the window to fit the form.  I have tried the suggestions in Microsoft KB article Q98598 with no success.
0
Comment
Question by:awd
[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
  • 14
  • 7
  • 6
  • +1
31 Comments
 
LVL 1

Expert Comment

by:malmq
ID: 1310846
Did you set ResizeParentToFit( TRUE ).  You may want to try setting it to FALSE.  At least the MSDN implies that the scroll bars MIGHT NOT appear.

The kind of resizing to perform. The default value, TRUE, shrinks the frame window if appropriate. Scroll bars will still appear for large views or small frame windows. A value of FALSE causes the view always to resize the frame window exactly. This can be somewhat dangerous since the frame window could get too big to fit inside the multiple document interface (MDI) frame window or the screen.
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 1310847
Couple that with OnMinMaxInfo handling to prevent shrinking the window to a size that will need scrollbars.
0
 
LVL 1

Author Comment

by:awd
ID: 1310848
Yes.  I tried both.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:danny_pav
ID: 1310849
Also look at SetScrollSizes()
0
 
LVL 1

Author Comment

by:awd
ID: 1310850
I am pretty new to doc's and views.  If anyone can be more specific and possibly post some code i can add more points.  Does anyone have direct experience with this?
0
 
LVL 1

Expert Comment

by:malmq
ID: 1310851
Here is a tidbit that worked for me.  The size was a value I calculated as the actual length and width that I wanted the view to be.                  

void CNotebookView::OnInitialUpdate()
{
.....
  SetScrollSizes(MM_TEXT, size);
  pWnd->RecalcLayout();
  ResizeParentToFit(FALSE);
  OnSize(0,0,0);
}

-malmq
0
 
LVL 1

Author Comment

by:awd
ID: 1310852
I am pretty new to doc's and views.  If anyone can be more specific and possibly post some code i can add more points.  Does anyone have direct experience with this?
0
 
LVL 1

Author Comment

by:awd
ID: 1310853
I will try that and let you know.
...looks like I accidentally reposted the last statement of mine.
0
 
LVL 1

Expert Comment

by:malmq
ID: 1310854
If it doesn't work, could your code for your view's OnInitialUpdate() method??

-malmq
0
 
LVL 1

Author Comment

by:awd
ID: 1310855
How can you determine the size of the dialog in the CFormView's client area?
0
 
LVL 1

Expert Comment

by:malmq
ID: 1310856
GetTotalSize( ) should do it.  A side note on my code, is that the size I was finding was a bitmap.  I'm not sure how you would determine the dialog size.  You could display it and then set some breakpoints and see what the size is.  You could then later hard code it.
0
 
LVL 1

Author Comment

by:awd
ID: 1310857
Here is what I have.  It "clips" off the OK button on the bottom right of my dialog.  It has a scrollbar on the right but not on the bottom.

void CVDFTView::OnInitialUpdate()
{
    CSize formSize;
    formSize = GetTotalSize();
    SetScrollSizes(MM_TEXT, formSize);
    GetParentFrame()->RecalcLayout();
    ResizeParentToFit(FALSE);
    OnSize(0,0,0);
}

0
 
LVL 1

Expert Comment

by:malmq
ID: 1310858
Okay one more try.  First go into your resouce editor and select the dialog you are tring to display.  Check the lower right hand corner for the size.  This is what I want you to put into the formSize variable.

Also, try the other change I made.

void CVDFTView::OnInitialUpdate()
{
    CMainFrame* pWnd = (CMainFrame*)AfxGetMainWnd();
 
    CSize formSize;
 //PUT SIZE IN HERE   formSize ;
    SetScrollSizes(MM_TEXT, formSize);
    pWnd->RecalcLayout();
    ResizeParentToFit(FALSE);
    OnSize(0,0,0);
}
0
 
LVL 1

Expert Comment

by:malmq
ID: 1310859
Is that your whole OnInitialUpdate??  You also should call the base OnInitialUpdate();

void CVDFTView::OnInitialUpdate()
{
    CMainFrame* pWnd = (CMainFrame*)AfxGetMainWnd();
 
    //ADD THIS!!
    CFormView::OnInitialUpdate();


    CSize formSize;
 //PUT SIZE IN HERE   formSize ;
    SetScrollSizes(MM_TEXT, formSize);
    pWnd->RecalcLayout();
    ResizeParentToFit(FALSE);
    OnSize(0,0,0);
}

0
 
LVL 1

Expert Comment

by:alex1234
ID: 1310860
Do this and you won't have scrollbars:

void CYourFormView::OnInitialUpdate()
{
      CFormView::OnInitialUpdate();

      //*** No scroll bars wanted.
      SIZE ts;

      ts.cx = 0;
      ts.cy = 0;

      SetScrollSizes(MM_TEXT, ts);
      ResizeParentToFit(FALSE);
}

0
 
LVL 1

Author Comment

by:awd
ID: 1310861
No.  This answer did not work.  It took the scrollbars off, but left the dialog "cropped" at the bottom.
0
 
LVL 1

Author Comment

by:awd
ID: 1310862
malmq,

Your last suggestion did not work either.  The window is not changing size.  It still has has a scrollbar on the right and I have to scroll down to see the bottom of the dialog. Any thoughts?
0
 
LVL 1

Expert Comment

by:alex1234
ID: 1310863
Do this:

void CYourForm::OnInitialUpdate()
{
      CFormView::OnInitialUpdate();

      CRect r;

      GetParent()->GetWindowRect(r);


      //*** No scroll bars wanted.
      SIZE ts;

      ts.cx = 0;
      ts.cy = 0;

      SetScrollSizes(MM_TEXT, ts);
      ResizeParentToFit(FALSE);


      GetParent()->SetWindowPos(
            &wndTop,
            r.left,
            r.top,
            r.Width(),
            r.Height(),
            SWP_NOZORDER
      );
}

0
 
LVL 1

Expert Comment

by:alex1234
ID: 1310864
awd, here is some improvement to always set your window at the top left corner:

void CYourForm::OnInitialUpdate()
{
CFormView::OnInitialUpdate();

CRect r;

GetParent()->GetWindowRect(r);


//*** No scroll bars wanted.
SIZE ts;

ts.cx = 0;
ts.cy = 0;

SetScrollSizes(MM_TEXT, ts);
ResizeParentToFit(FALSE);


GetParent()->SetWindowPos(
&wndTop,
0,
0,
r.Width(),
r.Height(),
SWP_NOZORDER
);
}

You may actually experiment with the position on your own to fit your particular needs.


0
 
LVL 1

Author Comment

by:awd
ID: 1310865
alex123,

The last suggestion worked, but there are 2 problems.
1. when the dialog comes up there are no scrollbars, BUT the okay button at the
bottom right of the dialog is clipped by the window.
2. If the user resizes the window the scrollbars do not come back, even when the
window is smaller than the dialog.
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 1310866
1. GetClientRect --> tthe window rect includes the size of the extra non client stuff.  the size you're setting is too small.
2. Set tthe total size to that size, then the scrollbars will reappear when it gets too small
0
 
LVL 1

Expert Comment

by:alex1234
ID: 1310867
awd,

there was a misunderstanding - I thought that you did't want scroll bars AT ALL, but it seems that you don't want them only initially when the window is displayed the first time.

Don't try my suggestion in the Proposed Answer then! It serves different purpose.

You may try danny_pav or others suggestion. Sorry.

0
 
LVL 1

Author Comment

by:awd
ID: 1310868
Ok.

So what would the code look like to do this?
I want the window to come up with the ENTIRE dialog showing and no scrollbars.
I also want the scrollbars to come back if the user szes the window to small.
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 1310869
void CXXView::OnInitialUpdate()
{
      CFormView::OnInitialUpdate();
      ResizeParentToFit(FALSE);

}


0
 
LVL 1

Author Comment

by:awd
ID: 1310870
danny_pav,

Using the code you just suggested does not work the way I need it to.  The window comes up with a scrollbar on the right and the ok button at the bottome of my dialog is "cutt-off".  Any suggestions?
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 1310871
it works fine for me.  Try this:

Go to AppWizard
Select new project, call it something like XX or Temp
select MDI and later make sure CXXView is derived from CFormView
and let it finish
Compile and run. close it.
now change the OnInitialUpdate to what I had above
compile and run.  

this should demonstrate that the problem is solved right?
you can check this by putting controls all over the CXXView's dialog resource
0
 
LVL 1

Author Comment

by:awd
ID: 1310872
After doing this it appears that the main frame is the one that is too small.  How do I get them all to size together.  The child frame is okay size-wise and behaves okay.  Now how do I get the main frame to do the same?
0
 
LVL 3

Accepted Solution

by:
danny_pav earned 450 total points
ID: 1310873
void CXXView::OnInitialUpdate()
{
      CFormView::OnInitialUpdate();
      ResizeParentToFit(FALSE);

      CFrameWnd * pFrame = GetParentFrame();
      pFrame->RecalcLayout();
      CRect rcWin;
      pFrame->GetWindowRect(rcWin);
      CFrameWnd * pMainFrame = pFrame->GetParentFrame();
      if (pMainFrame != NULL)
      {
            CRect rcMain;
            pMainFrame->GetWindowRect(rcMain);
            CWnd * pMDI = pMainFrame->GetWindow(GW_CHILD);
            CRect rcCli;
            pMDI->GetClientRect(rcCli);
            pMDI->ScreenToClient(rcWin);
            int nDiffHt = rcWin.bottom - rcCli.bottom;
            int nDiffWd = rcWin.right - rcCli.right;
            if (nDiffHt > 0)
                  rcMain.bottom += nDiffHt;
            if (nDiffWd > 0)
                  rcMain.right += nDiffWd;
            pMainFrame->SetWindowPos(NULL, 0, 0, rcMain.Width(), rcMain.Height(), SWP_NOZORDER | SWP_NOMOVE);
      }
}


0
 
LVL 1

Author Comment

by:awd
ID: 1310874
danny_pav,

Thanks.  I had no idea it would take so many lines of code to do that.  I will look at it and try and get this resolved (give you the points) tomorrow.
0
 
LVL 1

Author Comment

by:awd
ID: 1310875
danny_pav,

The last code sample you posted workd pretty good.  The only problem is that the main window is sized so that it has some extra space on the right.  It is a little wider than the client window now.  Otherwise, it works.  Any thoughts?
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 1310876
The sizing algorithm makes the size to allow the child window to fit at the point that it sits.  This could allow for more space than needed so that the child window does not have to be moved. You can alter the code to size to fit, and move the child window if necessary.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

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…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

704 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