Click here to Skip to main content
15,352,679 members
Articles / Programming Languages / C++
Posted 10 Dec 2001


287 bookmarked

EasySize - Dialog Resizing in No Time!

Rate me:
Please Sign up or sign in to vote.
4.95/5 (211 votes)
23 Mar 20074 min read
An easy way to position controls in resizable dialogs or property pages using just a few macros
In this article, you will learn to design your dialog the way you want it to look in the resource editor, and then define how the controls will behave when the dialog is resized using one single macro for each control.

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:
    class CEasySizeDemoDlg : public CDialog
  3. Create an OnInitDialog handler if it doesn't already exist, and put this in the end of it: "INIT_EASYSIZE;":
    BOOL CEasySizeDemoDlg::OnInitDialog()
        return TRUE; // return TRUE  unless you set the focus to a control
  4. Create an OnSize handler and add the UPDATE_EASYSIZE; macro to it:
    void CEasySizeDemoDlg::OnSize(UINT nType, int cx, int cy) 
        CDialog::OnSize(nType, cx, cy);
  5. Optional - If you want your dialog to have a minimum size, then create an OnSizing handler and add the EASYSIZE_MINSIZE macro as below:
    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)
  6. 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:

    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 your question in the board below). Obviously, ES_KEEPSIZE cannot be specified in both "left and right" or "top 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 cannot 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 that you will not even notice it.


  • 11th December, 2001: Initial version

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

QuestionGreat macro! But.. Pin
Luc Paquin24-Nov-21 2:50
MemberLuc Paquin24-Nov-21 2:50 
QuestionNice Job! Pin
Jake G6-Dec-20 21:18
MemberJake G6-Dec-20 21:18 
Generalit is amazing... Pin
Southmountain22-Aug-20 11:56
MemberSouthmountain22-Aug-20 11:56 
Questionactivex control Pin
Member 123847158-May-17 1:19
MemberMember 123847158-May-17 1:19 
QuestionEasy way to remove flickering Pin
Member 932558223-Jul-16 12:15
MemberMember 932558223-Jul-16 12:15 
Questioni have a question to use it Pin
Member 1251830812-May-16 1:00
MemberMember 1251830812-May-16 1:00 
Generalgreat Pin
xdjinjian4-Mar-15 2:42
Memberxdjinjian4-Mar-15 2:42 
QuestionERROR Pin
lhrlemon7-Nov-14 23:03
Memberlhrlemon7-Nov-14 23:03 
AnswerRe: ERROR Pin
Ujjwal Gangwal6-Oct-16 21:22
professionalUjjwal Gangwal6-Oct-16 21:22 
AnswerRe: ERROR Pin
ftai23-Jan-17 13:42
Memberftai23-Jan-17 13:42 
Questionthx Pin
youzhusuke18-Jun-14 20:43
Memberyouzhusuke18-Jun-14 20:43 
QuestionIn VS2010,this work can not work Pin
Somebody_anyone14-Jun-14 5:28
MemberSomebody_anyone14-Jun-14 5:28 
GeneralWorks Great! Thanks Pin
Member 91260194-Apr-14 22:08
MemberMember 91260194-Apr-14 22:08 
Questionnice Pin
me5252-Apr-14 19:41
Memberme5252-Apr-14 19:41 
Questiongood but.. Pin
Lord Hol Napult29-Jan-14 8:30
MemberLord Hol Napult29-Jan-14 8:30 
Questionthx Pin
hkcrazy2-Jan-14 5:33
Memberhkcrazy2-Jan-14 5:33 
Questiongreat Pin
张 vivian17-Dec-13 16:52
Member张 vivian17-Dec-13 16:52 
GeneralNice! Pin
mou_yq9-Dec-13 2:11
Membermou_yq9-Dec-13 2:11 
GeneralMy vote of 4 Pin
Miaoz13-Oct-13 18:24
MemberMiaoz13-Oct-13 18:24 
Questiongood Pin
liaoyungchun19-Aug-13 21:54
Memberliaoyungchun19-Aug-13 21:54 
GeneralMy vote of 5 Pin
kobe_guang22-Jan-13 15:34
Memberkobe_guang22-Jan-13 15:34 
Questionabout EASYSIAE micro Pin
November 201315-Jan-13 21:32
MemberNovember 201315-Jan-13 21:32 
GeneralMy vote of 5 Pin
tgis.top26-Nov-12 20:54
Membertgis.top26-Nov-12 20:54 
GeneralMy vote of 5 Pin
zhanglipeng22-Nov-12 15:34
Memberzhanglipeng22-Nov-12 15:34 
QuestionWould need a more version where windows can be added and removed dynamically Pin
llothar19-Nov-12 6:08
Memberllothar19-Nov-12 6:08 

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.