Click here to Skip to main content
14,429,185 members

EasySize - Dialog resizing in no time!

Rate this:
4.95 (209 votes)
Please Sign up or sign in to vote.
4.95 (209 votes)
23 Mar 2007
An easy way to position controls in resizable dialogs or property pages using just a few macros

Image 1

Image 2

Image 3


Have you ever thought of how annoying it actually was to spend a lot of time doing a basic GUI for your simple applications instead of focusing on the actual 'content'? Take for example a resizing dialog or property page. You need to write code for each control that will tell it where to go when the thing is resized, and this can take up a lot of time. Now I know that I'm not the first one to give a solution to this (CResizableDialog), but this article is on my approach.


Basically, all you need to do is design your dialog the way you want it to look in the resource editor (don't forget to make it resizable), and then define how the controls will behave when the dialog is resized using one single macro for each control.


Note that all this works exactly the same way with both CDialog and CPropertyPage

  1. #include EasySize.h to your stdafx.h (or put it in your include directory and #include <EasySize.h> , which I recommend)
  2. Add DECLARE_EASYSIZE anywhere in your class declaration:
  3. class CEasySizeDemoDlg : public CDialog
  4. Create an OnInitDialog handler if it doesn't already exist, and put this in the end of it: "INIT_EASYSIZE;" :
  5. BOOL CEasySizeDemoDlg::OnInitDialog()
        return TRUE; // return TRUE  unless you set the focus to a control
  6. Create an OnSize handler and add the UPDATE_EASYSIZE; macro to it:
  7. void CEasySizeDemoDlg::OnSize(UINT nType, int cx, int cy) 
        CDialog::OnSize(nType, cx, cy);
  8. Optional - If you want your dialog to have a minimum size, then create an OnSizing handler and add the EASYSIZE_MINSIZE macro as below:
  9. void CEasySizeDemoDlg::OnSizing(UINT fwSide, LPRECT pRect) 
        CDialog::OnSizing(fwSide, pRect);
    //(in this example, 280 is the minimum width and 250 the 
    //minimum height we want our dialog to have)
  10. Now you have to create the "EasySize Map" (or whatever you want to call it) in which you will specify the behavior of each dialog item. It can be placed anywhere inside your class implementation. The map looks like this:
  11. BEGIN_EASYSIZE_MAP(class_name)

    The map from the demo application looks like this:

    // CEasySizeDemoDlg message handlers

    Looks confusing? It's not once you get the point (and I know I'm not good at explaining it) Read on.


The EASYSIZE macro is used in the EasySize Map to specify what behavior your controls will have on dialog resize. It looks like this:


control is the ID of the dialog item you want re-positioned (which will be referred to as the 'current control' further on).

left, top, right and bottom can be either the ID of another control in the dialog (not the current control), or one of the special values, ES_BORDER and ES_KEEPSIZE.

Basically, if you specify an ID, the distance from the current control and the item designated by the ID will remain the same when the dialog is resized: The current control will 'stick' to the other item. ES_BORDER works the same way as if you had specified a control ID, except that it's the distance between the current control and the dialog border that will be kept constant. Specifying ES_KEEPSIZE in, let's say left, will keep the width of the current control the same, and will make the current control right-aligned to whatever you specified in right. The width (or height, if you specified ES_KEEPSIZE in top or bottom) of the current control will always remain what it is in the dialog resource. (I know this explanation sucks, but look at the demo application if you are confused or post you question in the board below). Obviously ES_KEEPSIZE cannot be specified in both "left and right" or

and bottom".

options can be a combination of ES_HCENTER, ES_VCENTER and 0 (use 0 if you don't want any of the other). ES_HCENTER horizontally centers the control between the two items specified in left and right (both of those can not be ES_KEEPSIZE!). The width of the current control will always remain the same as in the dialog resource. ES_VCENTER works the same way, but for vertical centering (using top and bottom, and where the height will remain constant).


Well I hope you figured out how this works, because it really can make your life easier. Note that using these macros will probably make your compiled code slightly bigger and slower than if you had coded the resizing routines manually, but in most cases the change is so small not even you will notice.

Last Update - Just corrected a few typos.


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

Marc Richarme
Engineer Nokia
Denmark Denmark
My programming experience started a long time ago in
QBasic (on a 25MHz 486).
I'm now mainly using Java, C++, C, MFC, Perl and PHP, but have used quite a number of other languages as well for various projects.

Comments and Discussions

GeneralAdjusting the size of column in List Control Pin
John Pinto16-Jun-09 3:19
MemberJohn Pinto16-Jun-09 3:19 
GeneralExcellent Pin
Milan121220-May-09 8:13
MemberMilan121220-May-09 8:13 
Questionhow to resize child dialogs in the tab control Pin
comberti15-Apr-09 0:20
Membercomberti15-Apr-09 0:20 
AnswerRe: how to resize child dialogs in the tab control Pin
bolonglx28-Aug-10 2:12
Memberbolonglx28-Aug-10 2:12 
GeneralRe: how to resize child dialogs in the tab control Pin
jamesprite14-Feb-12 23:50
professionaljamesprite14-Feb-12 23:50 
QuestionUpper Left resize not working Pin
Mitch Faatz3-Dec-08 13:24
MemberMitch Faatz3-Dec-08 13:24 
QuestionWhy I can not do it? Pin
tunnel11516-Oct-08 4:47
Membertunnel11516-Oct-08 4:47 
GeneralOnSizing is not working with FormViews [modified] Pin
irlm30-Sep-08 3:55
Memberirlm30-Sep-08 3:55 
GeneralThanks! Pin
Razmar12-Sep-08 13:12
MemberRazmar12-Sep-08 13:12 
QuestionHow can i make map for group button or icon with same horizontal gap in hcenter? Pin
shimjahyun31-Jul-08 3:58
Membershimjahyun31-Jul-08 3:58 
Questiontwo bugs! Pin
dreamwj15-May-08 0:55
Memberdreamwj15-May-08 0:55 
AnswerRe: two bugs! Pin
utakata4-Jun-08 20:06
Memberutakata4-Jun-08 20:06 
GeneralVery handy Pin
Agnostic116-Apr-08 9:20
MemberAgnostic116-Apr-08 9:20 
GeneralRe: Very handy Pin
dengniancai10-Mar-09 0:32
Memberdengniancai10-Mar-09 0:32 
Generaluse it in a cfromview Pin
sakuram14-Apr-08 20:13
Membersakuram14-Apr-08 20:13 
Generaleasy to use Pin
marshall20024-Apr-08 21:19
Membermarshall20024-Apr-08 21:19 
GeneralExcellent Article Pin
Mushtaque Nizamani15-Aug-07 20:27
MemberMushtaque Nizamani15-Aug-07 20:27 
GeneralCan't get it to work with CPropertyPage Pin
wjvdh11-May-07 13:53
Memberwjvdh11-May-07 13:53 
QuestionHow can i provide some offset between two controls Pin
avi_mcet11-May-07 2:53
Memberavi_mcet11-May-07 2:53 
QuestionHow to resize an ActiveX control? Pin
avi_mcet12-Apr-07 2:45
Memberavi_mcet12-Apr-07 2:45 
AnswerRe: How to resize an ActiveX control? Pin
chaiein6-Jan-12 22:03
Memberchaiein6-Jan-12 22:03 
QuestionNice job! Pin
prcarp23-Mar-07 9:33
Memberprcarp23-Mar-07 9:33 
Questionhow to implement the OnSizing message Pin
singersinger3-Dec-06 22:46
Membersingersinger3-Dec-06 22:46 
AnswerRe: how to implement the OnSizing message Pin
kodeguru8-Jan-07 9:21
Memberkodeguru8-Jan-07 9:21 
GeneralDerived Dialog Class Pin
Daniel Zuppinger18-Nov-06 7:30
MemberDaniel Zuppinger18-Nov-06 7:30 

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.

Posted 10 Dec 2001


285 bookmarked