Click here to Skip to main content
Click here to Skip to main content

Easy dialog control resizer

, 22 Sep 2003
Rate this:
Please Sign up or sign in to vote.
Simple implementation of "anchors" and "docking" features implemented in .NET forms

dialog window before resizing

dialog window after resizing


Yesterday when I wrote a simple Win32 dialog application, I missed one handy feature that is implemented in .NET forms; anchors and docking for controls. I took a look at the CodeProject, but I did not find exactly what I was looking for, so I wrote a simple solution for myself. I put it here with hope that it will be useful for some other programmers. This solution has two advantages. First is that, you can use this simple class in MFC and non-MFC applications too. Second is that you can use add/remove for dynamically created controls during running application.

Using the code

First of all, if you want to use this class in your application, you must include this header file:

#include "anchor.h"
CDlgAnchor dlgAnchor;
CDlgMan dlgMan;     

In WM_INITDIALOG handler routine or OnInitDialog (MFC applications), you must initialize this class:

static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, 
                                   WPARAM wParam, LPARAM lParam)
    switch (msg) {
      case WM_INITDIALOG:
        // load pos/sizes of dialog window and all child windows
        dlgMan.Load(hwndDlg, "Software\\CodeProject\\AnchorExample");

Now you can set anchors and/or docking for the controls you want from the list in the header file. You can use add/remove controls during the life of the dialog window as you will need, e.g. you can use Add function for dynamically created controls.

dlgAnchor.Add(IDC_EDIT1, ANCHOR_ALL);

Lastly you will need to add to the WM_SIZE handler routine, code that will execute the OnSize class routine, and add to the WM_DESTROY handler routine, code that will save window position and size.

case WM_SIZE:

That's all. I hope, you find this class useful.


  • 19 September 2003
    • Added Update and UpdateAll functions that you may use if some other dialog handler (like Splitter) will change size of controls.
    • Added helper class CDlgMan (saving/restoring window position and position of all child windows).
  • 11 September 2003
    • First release.


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

Web Developer
Slovakia Slovakia
No Biography provided

Comments and Discussions

GeneralMy vote of 5 Pinmemberwwputao11-May-11 1:58 
GeneralMy vote of 5 PinmemberRolf Kristensen6-Jan-11 5:47 
GeneralCheck this out... PinmemberMizan Rahman6-Dec-10 5:23 
GeneralMy vote of 5 Pinmemberfluke0123-Nov-10 18:03 
GeneralGreat stuff PinmemberCerberu525-Nov-08 1:52 
QuestionHow to keep two compenent equal in sizes when resize? Pinmembercgyonly26-Jun-08 5:41 
Questionsupplement,my UI like this... Pinmembercgyonly26-Jun-08 5:50 
GeneralToo sweet! Pinmemberpalanka19-Mar-08 10:33 
GeneralWorks great PinmemberWolferine423-May-07 9:34 
GeneralI can't use in MFC Pinmembersms911-Sep-06 20:27 
GeneralThanks.. PinmemberKim A31-May-06 5:25 
GeneralPicture Control PinmemberScaleOvenStove6-Feb-06 8:14 
GeneralRe: Picture Control PinmemberJenleonard7-May-06 16:33 
QuestionFit a Dialog into a view? Pinmemberrgchezhian8-Mar-05 5:16 
GeneralError Resize ActiveX controls (MSFlexGrid) PinmemberAlexFilan13-Jul-04 0:29 
GeneralRe: Error Resize ActiveX controls (MSFlexGrid) PinsussAnonymous13-Jul-04 1:50 
QuestionHow to Resize CStatusbar Object PinmemberKoundinya23-Apr-04 3:54 
Questioncan this be restricted to some minimum size ? PinmemberHabib Ahmed Qurashi3-Nov-03 18:34 
AnswerRe: can this be restricted to some minimum size ? Pinmemberuemaker3-Nov-03 22:38 
Generalwould you please... Pinmemberhongseman22-Oct-03 15:43 
QuestionCombatible with CSplitDialog? Pinmemberiknowindigo18-Sep-03 8:39 
AnswerRe: Combatible with CSplitDialog? Pinmemberiknowindigo18-Sep-03 10:45 
GeneralMy dialog doesn't size Pinmemberiknowindigo18-Sep-03 8:03 
GeneralRe: My dialog doesn't size Pinmemberuemaker18-Sep-03 8:18 
GeneralRe: My dialog doesn't size Pinmemberiknowindigo18-Sep-03 8:33 
GeneralRe: My dialog doesn't size Pinmemberuemaker18-Sep-03 8:44 
GeneralRe: My dialog doesn't size Pinmemberiknowindigo18-Sep-03 8:48 
GeneralRe: My dialog doesn't size Pinmemberuemaker18-Sep-03 8:32 
GeneralSorry, wrong article!! PinmemberLeandro Linhares Rodrigues17-Sep-03 5:03 
QuestionHow can use the CGfxOutBarCtrl in a Dialog Based Project? PinmemberLeandro Linhares Rodrigues17-Sep-03 4:59 
GeneralFlickering... PinmemberMandalay16-Sep-03 13:15 
GeneralRe: Flickering... PinmemberWolfSupernova16-Sep-03 18:12 
GeneralRe: Flickering... PinmemberMandalay17-Sep-03 7:20 
GeneralRe: Flickering... Pinsussrimer22-Sep-03 20:46 
GeneralRe: Flickering... PinmemberPaolo Messina23-Sep-03 18:31 
GeneralRe: Flickering... Pinmemberradioactiveman8422-Jan-08 3:06 
GeneralRe: Flickering... [modified] Pinmemberreversed7-Jul-06 8:37 
GeneralDoes not link. PinmemberWREY16-Sep-03 10:59 
GeneralRe: Does not link. Pinmemberuemaker16-Sep-03 11:25 
GeneralRe: Does not link. PinmemberWREY16-Sep-03 12:06 
GeneralRe: Does not link. Pinmemberuemaker16-Sep-03 13:17 
GeneralRe: Does not link. PinmemberWREY17-Sep-03 1:59 
GeneralLooks good... PinmemberWolfSupernova15-Sep-03 8:14 
GeneralRe: Looks good... Pinmemberuemaker15-Sep-03 8:21 
GeneralRe: Looks good... PinmemberWolfSupernova15-Sep-03 8:30 
GeneralRe: Looks good... Pinmemberuemaker15-Sep-03 8:48 
GeneralRe: Looks good... PinmemberWolfSupernova16-Sep-03 18:40 
GeneralRe: Looks good... PinmemberWolfSupernova17-Sep-03 2:50 

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
Web04 | 2.8.150327.1 | Last Updated 23 Sep 2003
Article Copyright 2003 by uemaker
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid