Easy Dialog, Property Sheet and Window Resizing

Environment: VC6, NT4, Win9x, WinXP

Dialog sizer

Code homepage - This is where updates will be found as and when they become available.


All too often we restrict the size of dialogs just so they fit onto smaller screens - this penalises those of us with larger monitors for no apparent reason. Sizeable windows, dialogs and property sheets can end much of the frustration for your users and provide a more pleasing and flexible UI.

I've seen many dialog resizing projects on codeguru.com and codeproject.com. They all seem to suffer from the same fate: They are complex to integrate into your current project, they require MFC projects to add control objects for every control or they are plain clumsy to use - or a combination of all three.

If you use MFC then they often require you to change your class hierarchy, deriving from their classes instead of your own custom classes. This is painful and is easy to avoid.

It's my aim to correct this, to provide a simple API that hopefully can be built upon to create clean and simple window manager.

What's it do

With a single function call you can make your dialogs, windows and property sheets resizable. This is complete with sizing and moving controls as the user resizes the window. DialogSizer optionally saves and restores the window position and size too.

DialogSizer will optionally add a sizing gripper to your windows giving your users valuable feedback about what can be resized and what can't. You can even optionally specify the largest size of your window.


The ZIP file contains two contrived examples, one for Win32 API and one for MFC. The MFC version demonstrates adding the library to a dialog, a property sheet and a view. The API example demonstrates just the dialog but the conventions remain the same for API and MFC (or any language I guess).

Let's look at an example, here's a simple dialog that is not resizable:

And here it is resizable:

And here is the simple code that makes it possible:

(void)DialogSizer_Set( hDlg, 
         NULL );


Docs are a pain but I'll do my best. The library is essentially very simple to use but to avoid confusion I've provided some basic docs.


Name of the structure

This is used to declare the begining of the description of how sizing should take place, you'll give this to the library


This is used to declare the end of the description of how sizing should take place.

extern "C" BOOL DialogSizer_Set( HWND hwnd, const DialogSizerSizingItem *psd, BOOL bShowSizingGrip, HKEY hkRootSave, LPCTSTR pcszName, SIZE *psizeMax );

The window handle to set as sizable
pointer to the sizing structure as built up by the macros.
TRUE if the sizing grip should be displayed, FALSE if not.
Registry root key to be used to store/retrieve the window size/position information in the registry. Can be NULL
Name that will be used to store/retrieve the window size/position information in the registry. Can be NULL only if hkRootSave is also NULL.
Pointer to the maximum size of window, NULL if you don't wish to use a maximum size.
Return value

FALSE if something failed, non-zero if everything went well

This is used to pass the sizing desciption to the library. DialogSizer_Set basically takes a copy of your description (so it can go out of scope) and then subclasses your window. It then takes care of all WM_SIZE messages (and a couple of others) to ensure correct behaviour.

DIALOG_SIZER_ENTRY( controlID, flags )

the ID of the control
The flags that describe how a control is sized.

This is the interesting bit. Using a combination of simple flags we can control how a control is moved and resized.

Add this flag to move a control in the X axis when the window is horizontally sized
Add this flag to move a control in the Y axis when the window is vertically sized
Add this flag to size a control in the X axis when the window is horizontally sized
Add this flag to move a control in the Y axis when the window is vertically sized

Say you only have an edit box on a dialog and nothing else. Then you would use flags of DS_SizeX | DS_SizeY.


This software is provided 'as-is', without any express or implied warranty.

In no event will the author be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation is requested but not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. Altered source is encouraged to be submitted back to the original author so it can be shared with the community. Please share your changes.
  3. This notice may not be removed or altered from any source distribution.

Source code notes

The bulk of the functionality is in the single source file DialogSizer_Set.cpp. You should feel free to add this source file to your core utilities to better integrate it into your system builds.

The source is built using level 4 warnings and warnings as errors. It will compile as-is with unicode.

I use the directory structure outlined here. You don't need to follow this but it's served me well for many years and I've had zero problems with it. All my stuff goes into this structure

Share any modifications you make with me so I can share them with others...help make this a better tool and let's help everyone else so they don't need to write the same thing again!

About the author

I'm a C++ developer with more years than I can remember.
Main day job is working on the rather fabulous PC based TV guide called DigiGuide.

My 'spare time' is occupied by writing either contract code or working on stuff for my own website, which includes QHTM - a rather nifty HTML rendering windows control.

I wrote this library *ages* ago but, as is always the case, once the fun(coding) bit is out of the way that only leaves writing the web pages, creating the zip files and uploading it - none of which is fun.

Hope you get as much use out of it as I have, and don't forget to share your mods!


  • Only source code Includes source for the library and the examples, plus any supporting files needed - 83 Kb
  • Compiled examples only So you can take a quick look and see if the library does what you expect - 39 Kb

This article was originally published on April 17th, 2002

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date