CDialogResize - Implement resizable dialogs using maps
Although there are a large number of MFC implementations of resizable dialogs, most of them do not provide a simple way to include them in your project. I was looking for a solution to add resizing to my dialogs which works someway similar to MFC's message maps and found one in the WTL classes from Microsoft: CDialogResize. Unfortunately you can not directly use this class in MFC, so I modified it a bit and decided to publish my modifications on this website.
I almost didn’t change anything to the original code, except a few ATL specific calls which I've ported to MFC equivalents.

Using CDialogResize
Add CDialogResize.cpp and CDialogResize.h to your project.

Include CDialogResize.h in the header of your dialog and derive it from CDialogResize instead of CDialog
and add DECLARE_DLGRESIZE_MAP; to the end of the class definition

#include CDialogResize.h

class CMyDialog : public CDialogResize

Add the following lines to the class implementation:


Call InitResizing() from CMyDialog::OnInitDialog():

BOOL CMyDialog::OnInitDialog()
 return TRUE;

And finally setup the resize map, which tells CDialogResize which controls to move or size:
An entry looks like this:


ControlID is the ID of the dialog control. The possible flags are:

DLSZ_SIZE_X: Resize the width of the control as the dialog resizes horizontally.
DLSZ_SIZE_Y: Resize the height of the control as the dialog resizes vertically.
DLSZ_MOVE_X: Move the control horizontally as the dialog resizes horizontally.
DLSZ_MOVE_Y: Move the control vertically as the dialog resizes vertically.
DLSZ_REPAINT: Invalidate the control after every move/resize so it repaints every time.

You can also group controls together so that they move and size proportionally to each other by using:

For more information how to use the several options check out my calculator example or go to: for more detailed information about WTL's CDialogResize class in an article by Michael Dunn .

Download demo executable

Download source code
This class is part of the Pablo Software Solutions MFC Extension Package - Classes Edition

[Home] [Products] [Source Code] [Downloads]

© 2015 - Pablo Software Solutions
All rights reserved.