Click here to Skip to main content
11,631,326 members (69,844 online)
Click here to Skip to main content


, 25 Jul 2012 CPOL 589K 12.2K 206
Rate this:
Please Sign up or sign in to vote.
A CDialog derived class to implement resizable dialogs with MFC

CResizableDialog - What is it & Why?

I wrote my own class to implement resizable dialogs mostly as an exercise of MFC and Windows programming. Later, I discovered that other people had written similar classes, but I didn't find one I really like that was as simple as my little projects.

Before you go any further, I have to warn you that I'm not a "guru". Surely something could be done better, but I think this class is at least easy to use.

The user will have the ability to resize the dialog, with consequent rearrangement of child windows, and you can control the minimum and maximum size allowed, as well as the maximized size and position of the dialog. The size grip is displayed by default, but you may turn it off. Automatic Save/Restore the dialog's size and position is also supported.

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

Now implemented with ResizableLib (see article).

The Sample Application

This is a view of the sample dialogs:

Default min size is the one in the dialog template (and grip is visible) Support for colored or bitmap background with a triangular size grip

This is a composite view, where you can see the maximized position is not the default:

A desktop snapshot with the dialog maximized and normal size overimpressed

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 dialog resource and associate it with a CDialog derived class, for example using Class Wizard, or take a dialog you have already made which you want to be resizable.

You no longer need to change the window style to have the dialog resizing.

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

Search and replace all CDialog occurrences with CResizableDialog in both your .cpp and .h files, just as if your dialog class was derived from CResizableDialog instead of CDialog. 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:

// MyDialog.h : header file
// ( Class Wizard stuff )
// CMyDialog dialog

#include "ResizableDialog.h"
class CMyDialog : public CResizableDialog
// Construction
    CMyDialog(CWnd* pParent = NULL);    // standard constructor

// ( other stuff )
// ...

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

BOOL CMyDialog::OnInitDialog()

    // Set the icon for this dialog. The framework does this
    // automatically when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);     // Set big icon
    SetIcon(m_hIcon, FALSE);    // Set small icon

    // preset layout
    AddAnchor(IDOK, BOTTOM_RIGHT);
    AddAnchor(IDC_SPIN1, TOP_RIGHT);

    AddAnchor(IDC_LABEL1, TOP_LEFT);

    // other initializations
    // ...

Here you may also set a maximum size for your dialog (default is the workspace area), a minimum size (default is the one you set in the resource editor) and also a rectangle that the dialog occupies when maximized.

// get desktop size
CRect rc;

// set max tracking size to half a screen
SetMaxTrackSize(CSize(rc.Width(), rc.Height()/2));

// maximized position and size on top of the screen
rc.bottom = 100;

After all this settings, you may wish the dialog's size and position to be automatically saved and restored, as well as its maximized or minimized state. Just provide a Section and an Entry name in your application's profile, in which to save dialog's status.

// save/restore
// (for dialog based app, default is a .INI file with
// the application's name in the Windows directory)

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

For further details, see the next section.

Class Reference

This class inherits from CResizableGrip, CResizableLayout, CResizableMinMax, CResizableState, and obviously from CDialog.


CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL)
CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL)

The first is the default constructor.

The second and the third forms are needed to reproduce the construction scheme of a CDialog derived class. Since the dialog resource template is needed by the CDialog constructor, you have to call one of these forms of the CResizableDialog constructor. This is the reason why replacing one class with the other will work.


void EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly = FALSE)

Enables automatic save/restore on dialog's open/close operations. The arguments are the same as in CWinApp::WriteProfileString. If bRectOnly is TRUE, the minimized/maximized state is not saved/restored. Should be called after all the layout settings.

If you want details on how this information is stored by your application, look at CWinApp::SetRegistryKey, CWinApp::m_pszProfileName, CWinApp::m_pszRegistryKey on MFC documentation.


Implemented in the various base classes, see ResizableLib article.


I would like to make this class more "integrated" with Class Wizard, but I don't even know if it's possible. I hope this class can be useful to other programmers that just want to have resizable dialogs with the minimum effort.

I implemented a sort of percentage resizing. However, currently available anchor types do not permit a high level of complexity, but should be enough in many applications. If you want more flexibility or if your dialogs are very big and full of controls, you may search CodeProject for another solution in this same Section (see the top of the article).

The CVS tree is now on Source Forge.


25 May 2000

  • Initial public release.

31 May 2000

  • Some unneeded code has been removed.
  • Flickering has been reduced for Button, Static and ListBox controls.
  • Save/Restore support has been added.
  • Fixed a nasty bug that only came out with modeless dialogs.

9 Jun 2000

  • Now compiles cleanly at warning level 4.
  • Memory leak fixed. (I completely forgot to free memory)
  • New type of anchorage now allowing more complex layouts. (compatible with previous code)
  • Fixed a bug with the size grip when hidden and when the dialog is maximized.
  • Better handling of controls that need repainting.
  • Demo project updated to show new features.

11 Jul 2000

  • Fixed a minor bug in save/restore functions. (standard maximized dialog wasn't restored correctly)

27 Oct 2000

  • Changed layout implementation (from CPtrList to CArray)
  • Fixed a bug with controls that need refresh

23 Nov 2000

  • Fixed a bug with multiple calls to DoModal()
  • Removed doc from zip files (you simply save this page if you need it)

13 Mar 2001

  • Fixed a bug with radio buttons and group boxes (thanks to Matt Philmon)
  • Changed copyright note

11 Jun 2001

  • New implementation and integration with ResizableLib
  • Automatic resizing style (thanks to John Simmons)
  • Added anti-flickering support

15 Jul 2001

  • Updated to new ResizableLib release
  • Demo project shows new grip implementation

28 Oct 2001

  • Version 1.1 (CVS Tag: SF_1_1)
  • Added static build configurations to all projects


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Paolo Messina
Software Developer RoboTech srl
Italy Italy
Paolo began programming at the age of 9 with a glorious 8086 and GW-BASIC, then he played a bit with C, ASM and Pascal. He tought himself MFC and Windows programming, to exploit his studies of C++. Always attracted by low-level programming and Assembly, he's beginning to appreciate the joys of templates and STL. At work he changed his mind about Java, discovered Eclipse IDE, and now think it's cool.

He lives in Follonica, Italy.

He has been abroad in the U.S. to work on his final thesis before graduating. For seven months he was playing with airplanes and automatic control at the Unversity of Illinois at Urbana-Champaign.

He graduated in Computer Science Engineering at the University of Pisa, Italy, in December 2003.

Currently working for an edutainment robotics company (

You may also be interested in...

Comments and Discussions

GeneralRe: Replacing CDialog instances Pin
WolfSupernova30-Sep-03 7:14
memberWolfSupernova30-Sep-03 7:14 
GeneralRe: Replacing CDialog instances Pin
Paolo Messina30-Sep-03 8:49
memberPaolo Messina30-Sep-03 8:49 
GeneralRe: Replacing CDialog instances Pin
WolfSupernova30-Sep-03 10:09
memberWolfSupernova30-Sep-03 10:09 
GeneralRe: Replacing CDialog instances Pin
Paolo Messina30-Sep-03 13:05
memberPaolo Messina30-Sep-03 13:05 
GeneralRe: Replacing CDialog instances Pin
WolfSupernova1-Oct-03 8:17
memberWolfSupernova1-Oct-03 8:17 
GeneralRe: Replacing CDialog instances Pin
Paolo Messina1-Oct-03 9:02
memberPaolo Messina1-Oct-03 9:02 
GeneralRe: Replacing CDialog instances Pin
WolfSupernova1-Oct-03 9:19
memberWolfSupernova1-Oct-03 9:19 
GeneralRe: Replacing CDialog instances Pin
WolfSupernova1-Oct-03 10:04
memberWolfSupernova1-Oct-03 10:04 
GeneralRe: Replacing CDialog instances Pin
Paolo Messina1-Oct-03 10:28
memberPaolo Messina1-Oct-03 10:28 
GeneralRe: Replacing CDialog instances Pin
WolfSupernova4-Oct-03 14:15
memberWolfSupernova4-Oct-03 14:15 
GeneralRe: Replacing CDialog instances Pin
Paolo Messina4-Oct-03 16:35
memberPaolo Messina4-Oct-03 16:35 
GeneralRe: Replacing CDialog instances Pin
WolfSupernova5-Oct-03 9:32
memberWolfSupernova5-Oct-03 9:32 
GeneralRe: Replacing CDialog instances Pin
Paolo Messina5-Oct-03 12:05
memberPaolo Messina5-Oct-03 12:05 
GeneralRe: Replacing CDialog instances Pin
Calder17-Jan-04 3:58
memberCalder17-Jan-04 3:58 
Please let us all know where on SourceForge we can find the new project... Thinking about adding resizing to my App, based on a skinnable dialog...Smile | :)
GeneralNews Pin
Paolo Messina17-Jan-04 7:14
memberPaolo Messina17-Jan-04 7:14 
GeneralRe: Replacing CDialog instances Pin
Ejaz11-Sep-07 3:29
memberEjaz11-Sep-07 3:29 
Generalcompiler error Pin
Gleason26-Sep-03 8:43
sussGleason26-Sep-03 8:43 
GeneralRe: compiler error Pin
Paolo Messina26-Sep-03 9:10
memberPaolo Messina26-Sep-03 9:10 
GeneralRe: compiler error Pin
Gleason26-Sep-03 9:41
memberGleason26-Sep-03 9:41 
GeneralRe: compiler error Pin
Paolo Messina26-Sep-03 10:04
memberPaolo Messina26-Sep-03 10:04 
GeneralRe: compiler error Pin
Gleason26-Sep-03 13:37
memberGleason26-Sep-03 13:37 
GeneralRe: compiler error Pin
Paolo Messina26-Sep-03 14:13
memberPaolo Messina26-Sep-03 14:13 
GeneralRe: compiler error Pin
Gleason26-Sep-03 14:24
memberGleason26-Sep-03 14:24 
GeneralRe: compiler error Pin
Paolo Messina27-Sep-03 12:51
memberPaolo Messina27-Sep-03 12:51 
GeneralResizable Picture can't be updated! Pin
Kyeongsik Ock27-Aug-03 15:18
memberKyeongsik Ock27-Aug-03 15:18 
GeneralRe: Resizable Picture can't be updated! Pin
Paolo Messina28-Aug-03 4:49
memberPaolo Messina28-Aug-03 4:49 
GeneralRe: Resizable Picture can't be updated! Pin
Kyeongsik Ock7-Sep-03 22:49
memberKyeongsik Ock7-Sep-03 22:49 
GeneralControl Problem Pin
Kreg6-Jun-03 6:59
memberKreg6-Jun-03 6:59 
GeneralRe: Control Problem Pin
Paolo Messina6-Jun-03 8:35
memberPaolo Messina6-Jun-03 8:35 
GeneralRe: Control Problem Pin
Kreg9-Jun-03 4:52
memberKreg9-Jun-03 4:52 
GeneralEasy problem but I'm new at this... Pin
WolfSupernova29-May-03 8:28
memberWolfSupernova29-May-03 8:28 
GeneralRe: Easy problem but I'm new at this... Pin
Paolo Messina29-May-03 10:28
memberPaolo Messina29-May-03 10:28 
GeneralGot some Error when compling. Pin
kyoshiro22-Apr-03 22:08
memberkyoshiro22-Apr-03 22:08 
GeneralRe: Got some Error when compling. Pin
Paolo Messina23-Apr-03 4:57
memberPaolo Messina23-Apr-03 4:57 
GeneralRe: Got some Error when compling. Pin
kyoshiro23-Apr-03 22:49
memberkyoshiro23-Apr-03 22:49 
GeneralRe: Got some Error when compling. Pin
Paolo Messina26-Apr-03 5:32
memberPaolo Messina26-Apr-03 5:32 
GeneralRe: Got some Error when compling. Pin
kyoshiro27-Apr-03 23:38
memberkyoshiro27-Apr-03 23:38 
Generalthe resizer isn't visible Pin
liquidsnake18323-Mar-03 10:15
memberliquidsnake18323-Mar-03 10:15 
GeneralRe: the resizer isn't visible Pin
Paolo Messina23-Mar-03 11:02
memberPaolo Messina23-Mar-03 11:02 
GeneralThere is a little problem Pin
Panda_w18-Mar-03 13:13
memberPanda_w18-Mar-03 13:13 
GeneralRe: There is a little problem Pin
Paolo Messina22-Mar-03 11:16
memberPaolo Messina22-Mar-03 11:16 
GeneralRe: There is a little problem Pin
Panda_w23-Mar-03 13:38
memberPanda_w23-Mar-03 13:38 
GeneralRe: There is a little problem Pin
Paolo Messina23-Mar-03 13:48
memberPaolo Messina23-Mar-03 13:48 
GeneralFind a bug Pin
Anonymous23-Oct-02 4:48
memberAnonymous23-Oct-02 4:48 
GeneralRe: Fixed Pin
Paolo Messina21-Mar-03 10:00
memberPaolo Messina21-Mar-03 10:00 
Questionresizing child windows?? Pin
Anthony Winters19-Jun-02 8:33
memberAnthony Winters19-Jun-02 8:33 
AnswerDisreguard resizing child windows?? New Problem!! Pin
AnthonyWinters19-Jun-02 9:27
memberAnthonyWinters19-Jun-02 9:27 
GeneralDisreguard??? Pin
Paolo Messina21-Jun-02 6:18
memberPaolo Messina21-Jun-02 6:18 
GeneralA greate job,but.... Pin
Panda_w27-Apr-02 20:26
memberPanda_w27-Apr-02 20:26 
GeneralRe: A greate job,but.... Pin
Paolo Messina28-Apr-02 11:00
memberPaolo Messina28-Apr-02 11:00 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150723.1 | Last Updated 25 Jul 2012
Article Copyright 2000 by Paolo Messina
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid