ATL Constraint Manager

By Horst Veith [hveith@intercom.at]
with Chris Sells [csells@sellsbrothers.com]

The Problem

Windows with child controls often need to resize. This includes dialogs, form views, dialog bars and plain windows that happen to have child windows taking up space. Windows provides no built in support. Horst has build a constraint manager class to add support to raw Win32 applications, ATL applications, WTL applications and MFC applications. atlconstraintmgr.h is the result.

A Solution

The atlconstraintmgr.h class allows for any parent window to resize its children via constraints, where a constraint defines how the child window will be moved and/or resized as the parent window resizes. To use the constraints, you derive your parent window class from CWndConstraintMgr (or CPropSheetConstraintMgr), chain to the base class message map and add your constraint map, like so:

class CFooDlg :
    public CDialogImpl<CFooDlg>,
    public CWndConstraintMgr<CFooDlg>
{
    ...
    BEGIN_MSG_MAP(CFooDlg)
        CHAIN_MSG_MAP(CWndConstraintMgr<CFooDlg>)
    END_MSG_MAP()
    
    BEGIN_CONSTRAINT_MAP(CFooDlg)
        CONSTRAINT_ENTRY(IDC_CTRL1, Fixed, Shift)			
        CONSTRAINT_ENTRY(IDC_CTRL2, Expand, Expand)			
        CONSTRAINT_ENTRY_RECT(IDC_CTRL3, 50, 0, 50, 0)
    END_CONSTRAINT_MAP()
    ...
};

A Sample

A fairly complete sample is available here. The sample implements the following resizeable dialog:

Small:

Big:

Enjoy.