Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ResizableFormView

0.00/5 (No votes)
27 Oct 2001 1  
A CFormView derived class to implement resizable form views with MFC

CResizableFormView

This class handles resizable Form views and it's based on my ResizableLib class library (see article).

The user will have the ability to resize the Form, with consequent rearrangement of child windows. If the Form window gets smaller than its minimum size, it becomes scrollable like standard CFormView.

Conversion of a previously existant Form should be very simple, as well as creation of a new resizable dialog.

The Sample Applications

This is a view of the SDI application:

A SDI application with resizable Form View

This is a view of the MDI application:

A MDI application with resizable Form View

You may see how to do this in the next section.

Usage - Step by Step

Add the ResizableLib to your project's workspace, as explained in the relative article.

Create a standard Form view or take one you have already made which you want to be resizable.

Include 'ResizableFormView.h' in the associated header file.

Search and replace all CFormView occurrences with CResizableFormView in both your .cpp and .h files, just as if your dialog class was derived from CResizableFormView instead of CFormView. I think there's no way to let the Class Wizard do this for you. Let me know if I'm wrong, please.

Your header file should appear like this:

#include "ResizableFormView.h"

class CMyFormView : public CResizableFormView
{
protected: // create from serialization only
    CMyFormView();
    DECLARE_DYNCREATE(CMyFormView)


// ( other stuff )
// ...
}

In your OnInitialUpdate override, add an anchor for each control you want the size and/or position to be changed when the user resizes the Form.

void CMyFormView::OnInitialUpdate()
{
    // must add controls to the layout
    // before OnInitialUpdate base implementation
    AddAnchor(IDC_LIST1, TOP_LEFT, BOTTOM_RIGHT);
    AddAnchor(IDC_GROUP1, TOP_LEFT, BOTTOM_LEFT);

    // complete initialization
    CResizableFormView::OnInitialUpdate();

    // these two lines are optional
    GetParentFrame()->RecalcLayout();
    ResizeParentToFit();
}

You are ready to rebuild your project and you will have a resizable Form view just as you wanted.

For further details, see the next section.

Class Reference

This class inherits only from CResizableLayout and obviously from CFormView. It just needs basic resizing capabilities.

CResizableFormView::CResizableFormView

CResizableFormView(UINT nIDTemplate)
CResizableFormView(LPCTSTR lpszTemplateName)
These are needed to reproduce the construction scheme of a CFormView derived class. This is the reason why replacing one class with the other will work.

CResizable???::???

Implemented in the various base classes, see ResizableLib article.

Conclusion

Even this class is eventually integrated with ResizableLib. Many thanks to John Simmons for his first attempt to make resizable Form views and for pointing out the scrolling problem. To solve it I had to add more functionalities to CResizableLayout, that could be useful for other purposes.

The CVS tree is now on Source Forge.

License

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