Click here to Skip to main content
11,796,774 members (69,671 online)
Click here to Skip to main content

Easy dialog control resizer

, 22 Sep 2003 173.1K 6.2K 80
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

You may also be interested in...

Comments and Discussions

GeneralRe: Flickering... Pin
Mandalay17-Sep-03 6:20
memberMandalay17-Sep-03 6:20 
GeneralRe: Flickering... Pin
rimer22-Sep-03 19:46
sussrimer22-Sep-03 19:46 
GeneralRe: Flickering... Pin
Paolo Messina23-Sep-03 17:31
memberPaolo Messina23-Sep-03 17:31 
GeneralRe: Flickering... Pin
radioactiveman8422-Jan-08 2:06
memberradioactiveman8422-Jan-08 2:06 
GeneralRe: Flickering... [modified] Pin
reversed7-Jul-06 7:37
memberreversed7-Jul-06 7:37 
GeneralDoes not link. Pin
WREY16-Sep-03 9:59
memberWREY16-Sep-03 9:59 
GeneralRe: Does not link. Pin
uemaker16-Sep-03 10:25
memberuemaker16-Sep-03 10:25 
GeneralRe: Does not link. Pin
WREY16-Sep-03 11:06
memberWREY16-Sep-03 11:06 
Getting an executable built is the goal, how it is done is another matter.

Having source files, a workspace file and a project file, then run a compile, will create an ".exe" file if everything runs well. That is the normal and common procedure when using MS IDE (at least for VC++ 6.0). In this case, it didn't produce an ".exe" file from your sample. The Debug folder showed no such file.

Your approach of simply typing "NMAKE" at the commmandline, I don't know about, but I followed your instruction anyhow and if it built an executable file, it did it someplace else because I sure didn't see one in the directory I was using, and neither did the sample run (meaning, there was no output shown).

Here is the error message from the link process.
example.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls@0
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/DialogCtrlResizer.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

Bottom line: I still don't have a clean compile and link.

Hmmm | :|


Fortes in fide et opere!
GeneralRe: Does not link. Pin
uemaker16-Sep-03 12:17
memberuemaker16-Sep-03 12:17 
GeneralRe: Does not link. Pin
WREY17-Sep-03 0:59
memberWREY17-Sep-03 0:59 
GeneralLooks good... Pin
WolfSupernova15-Sep-03 7:14
memberWolfSupernova15-Sep-03 7:14 
GeneralRe: Looks good... Pin
uemaker15-Sep-03 7:21
memberuemaker15-Sep-03 7:21 
GeneralRe: Looks good... Pin
WolfSupernova15-Sep-03 7:30
memberWolfSupernova15-Sep-03 7:30 
GeneralRe: Looks good... Pin
uemaker15-Sep-03 7:48
memberuemaker15-Sep-03 7:48 
GeneralRe: Looks good... Pin
WolfSupernova16-Sep-03 17:40
memberWolfSupernova16-Sep-03 17:40 
GeneralRe: Looks good... Pin
WolfSupernova17-Sep-03 1:50
memberWolfSupernova17-Sep-03 1: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.151002.1 | Last Updated 23 Sep 2003
Article Copyright 2003 by uemaker
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid