Class to Auto-Position Controls on Window Resize
Rating: none
|
Paul Wendt () November 3, 2000 |
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.
class CYourDialog : public CDialog
{
...
CControlPos m_cControlPos;
- In the OnInitDialog (or InitialUpdate) function, set the object's parent window
BOOL CYourDialog::OnInitDialog()
...
m_cControlPos.SetParent(this);
...
- After the call to CControlPos::SetParent, Add the controls you want to resize.
m_cControlPos.AddControl(IDOK, CP_MOVE_HORIZONTAL);
m_cControlPos.AddControl(IDCANCEL, CP_MOVE_HORIZONTAL);
- 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.
void CYourDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
m_cControlPos.MoveControls();
}
Downloads
阅读(1003) | 评论(0) | 转发(0) |