Click here to Skip to main content
13,456,463 members
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 3 Feb 2001

Resize MDI Child Frame Windows to Fit Form Views

, 16 Apr 2001
Rate this:
Please Sign up or sign in to vote.
Make the MDI windows which contain your program's forms snap to match the forms' sizes.

 [Sample Image - 25K]


Many applications allow the user to input and edit data using forms. If this is done in an MDI environment, managing the sizes of the MDI frame windows in which the forms are displayed can look like a daunting task. This article shows you how to call MFC functions to size the MDI child frame window to fit the form contained in the form view within it.

Resize Your Form With MFC!

Look in your derived form view class for a CFormView::OnInitialUpdate() function override. This is usually inserted for you if you created the form view class with AppWizard or ClassWizard. Go to the location of the implementation of the override in your code. Next, look for a call to ResizeParentToFit() that is on a line by itself. If you find such a call, replace the line with the code shown in bold below. If there is no such call, then add the code shown in bold to the implementation of OnInitialUpdate():

void CMyFormView::OnInitialUpdate()


The size of the client area of the view's MDI child frame window should now match the size of the dialog template used to place the controls on the form.

Don't Resize or Maximize!

The sample code provided with this article shows how to resize your form view frame windows to fit their forms, as outlined above. However, you probably don't want the user to be able to resize or maximize the window thereby defeating the purpose of calling CScrollView::ResizeParentToFit(). This is because MFC places the form in the top right corner of the client area of the MDI Child frame window. If you want to prevent the user from resizing or maximizing the frame window, disable the WS_THICKFRAME and WS_MAXIMIZEBOX styles, and add the WS_BORDER style to the window. This can be easily done using the CMDIChildWnd::PreCreateWindow() override placed in your code for you by AppWizard. This is, of course, usually in a CChildFrame class. Here's how the sample does it:

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
    if( !CMDIChildWnd::PreCreateWindow(cs) )
        return FALSE; &= ~(WS_THICKFRAME); &= ~(WS_MAXIMIZEBOX); |= WS_BORDER;

    return TRUE;


If you have any questions about what I've done with these techniques, please feel free to contact me anytime, or post a message in the message board below!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Brian C Hart
Software Developer (Senior) xyLOGIX, LLC
United States United States
From Fridley, Minnesota and I like computer programming! When I got started, I was working mostly with Windows GUI programming in C/C++. Then later on I worked with COM/DCOM for a school internship. I used COM/DCOM to write an ad hoc cluster server and job-running environment for a cluster of 24 Windows-based high-end visualization workstations. I moved on to C# and have been working in C# and Windows Forms ever since. I have yet to embrace Silverlight Smile | :)

You may also be interested in...

Comments and Discussions

GeneralMFC Form View Pin
Sir Chandresque14-Jun-02 8:49
memberSir Chandresque14-Jun-02 8:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04-2016 | 2.8.180322.1 | Last Updated 17 Apr 2001
Article Copyright 2001 by Brian C Hart
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid