Resizable Dialog Box

CResizingDialog is a CDialog derived class that allows the dialog controls to be reordered
and resized with the Dialog Box.

To use CResizingDialog :

  1. Replace the base class of your dialog box to CResizingDialog (instead of CDialog)
  2. Change the dialog template to allow resizing border.
  3. From the dialog constructor call SetConrolInfo() to set the behavior of
    each of your dialog controls on resize.

SetConrolInfo() determines how each control behaves when the user resize the dialog box.
The "Windows default" is ANCHORE_TOP | ANCHORE_LEFT) e.g.

For a right aligned OK button you’ll probably call:
SetControlInfo(IDOK, ANCHORE_RIGHT)
For a text control that needs to resize with the dialog you may do:
SetControlInfo(IDD_MYEDITOR, RESIZE_BOTH)

/////////////////////////////////////////////////////////////////////////////
// CSampleDlg dialog

CSampleDlg::CSampleDlg(CWnd* pParent /*=NULL*/)
: CResizingDialog(CSampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSampleDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
CDWordArray c_info;
SetControlInfo(IDC_LEFT_RESIZE, RESIZE_HOR | RESIZE_VER);
SetControlInfo(IDC_BOTTOM_ANCHORE, ANCHORE_BOTTOM | RESIZE_HOR);
SetControlInfo(IDOK, ANCHORE_RIGHT);
SetControlInfo(IDCANCEL, ANCHORE_RIGHT);
SetControlInfo(IDC_RIGHT_VER_RESIZE, ANCHORE_RIGHT | RESIZE_VER);
SetControlInfo(IDC_SLIDER1, ANCHORE_RIGHT | RESIZE_VER);

}

void CSampleDlg::DoDataExchange(CDataExchange* pDX)
{
CResizingDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSampleDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSampleDlg, CResizingDialog)
//{{AFX_MSG_MAP(CSampleDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSampleDlg message handlers

void CSampleDlg::OnOK()
{
CResizingDialog::OnOK();
}

Download demo project (with Source) – 22 KB

Download class only source – 4 KB

Date Last Updated: January 25, 1999

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read