You could use the CDialogResize
class for this. Simply inherit from this class in the class
definition of your window and define the way in which each control should resize as the window
is updated. These resizes cascade, so you can have a window that is resized in one way that also implements CDialogResize
.
class CFooWindow : ... public CDialogResize<CFooWindow> {
BEGIN_MSG_MAP(CFooWindow)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
... more messages here
CHAIN_MSG_MAP(CDialogResize<CFooWindow>)
END_MSG_MAP()
// This map defines how the controls within the window are resized.
// You can also use DLGRESIZE_GROUP() to group controls together.
BEGIN_DLGRESIZE_MAP(CFooWindow)
DLGRESIZE_CONTROL(IDC_WINDOW_TOP, DLSZ_SZIZE_X | DLSZ_SIZE_Y);
DLGRESIZE_CONTROL(IDC_WINDOW_BOTTOM, DLSZ_SZIZE_X | DLSZ_MOVE_Y);
END_DLGRESIZE_MAP()
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
DlgResize_Init();
}
.. the rest of your class here
}
You can implement the gaps between the controls by having a DLGRESIZE_GROUP()
and separating the controls in the resource file as you would like them to be separated in the final layout. The size
of the items will then be updated. If you need anything too complex you can use the dialog resize callback to control the exact placement of an item. Just implement CDlgResize::OnSize(UINT nType, int cx, int cy)
in your class and manually update the size of the control.