Introduction
Have you ever wanted to resize a window but NOT have to deal with all
of that annoying control-repositioning? What a hassle! Here is an easy-to-use class
that should provide a good foundation for anyone wishing to easily reposition controls
when a user resizes the parent window.
Usage
In order to use this class, simply follow these steps:
- Create a CControlPos member variable in your CDialog (used in example) or CView derived class.
- In the OnInitDialog (or InitialUpdate) function, set the object’s parent window
- After the call to CControlPos::SetParent, Add the controls you want to resize.
- Finally, on your WM_SIZE handler, call the object’s MoveControls to specify runtime behaviour. move all of the controls. Controls can be moved
horizontally and vertically and resized horizontally and vertically.
class CYourDialog : public CDialog { ... CControlPos m_cControlPos;
BOOL CYourDialog::OnInitDialog() ... m_cControlPos.SetParent(this); ...
m_cControlPos.AddControl(IDOK, CP_MOVE_HORIZONTAL); m_cControlPos.AddControl(IDCANCEL, CP_MOVE_HORIZONTAL);
void CYourDialog::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); m_cControlPos.MoveControls(); }