Download source files - 7 Kb
Download demo project - 30 Kb
Introduction
The CResizeCtrl
implements the ResizePercentage
method of the WCL (the framework of Optima++ alias Power++, which was dropped by Sybase).
For each control left, top, width and height is specified, to determine how the position and size of the control windows will change when the size of the parent window changes.
left specifies the change in the position of the left edge of the object relative to the total change in the parent window’s width.
For example: Suppose that left is 50 and the width of the window increases by 200 pixels, then the left edge of the object moves right by 100 pixels (50% of 200).
top specifies the change in the top position of the object relative to the total change in the parent window’s height.
For example: Suppose that top is 40 and the height of the window decreases by 20 pixels, then the top edge of the object moves up by 8 pixels (40% of 20).
width specifies the change in the width of the object relative to the total change in the parent window’s width.
For example: Suppose that width is zero. Then the width of the object does not change, regardless of how much the width of the parent window changes.
Or suppose that width is 100 and the width of the window decreases by 50 pixels, then the width of the object also decreases by 50 pixels (100% of 50).
height specifies the change in the height of the object relative to the total change in the parent window’s height.
For example: Suppose that height is 20 and the height of the parent's window decreases by 50 pixels, then the height of the object also decreases by 10 pixels (20% of 50).
The valid range for each parameter is 0 to maxPart, but also the sum of left + width and top + height must be less than or equal to maxPart
In general, the following formula is used
newValue = oldValue + (( deltaValueParent * partValue) / maxPart )
where:
newValue | is the new left or top position or new width or height |
oldValue | is the old left or top position or old width or height |
deltaValueParent | is the changes in parent width or height
|
partValue | is the left, top, width or height value specified in the Add Method |
maxPart | is the value specified by the maxPart parameter of the constructor or the Create method |
The default value for maxPart is 100, for a better degree of granularity another value can be specified in the Constructor or Create method
Example :
m_resize.Create( this );
m_resize.Add( IDC_EDIT1, 0, 0, 100, 50 );
m_resize.Add( IDC_LIST1, 0, 50, 100, 50 );
m_resize.Add( IDOK, 50, 100, 0, 0 );
m_resize.SetMinimumTrackingSize();
When the width of the parent's window increases by 40 pixels and the height increases by 20 pixels:
IDC_EDIT1: left += 0 top += 0 width += 40 height += 10
IDC_LIST1: left += 0 top += 10 width += 40 height += 10
IDOK : left += 20 top += 20 width += 0 height += 0
Usage :
Add the file 'ResizeCtrl.cpp' and 'ResizeCtrl.h" to your project
Because CResizeCtrl
can change the style of the dialogbox, it is not necessary to add a resizable border to the dialog template.
Include "ResizeCtrl.h' in the associated header file and add the CResizeCtrl
to the instance data of your dialog class
#include "ResizeCtrl.h"
class CDemoDialog : public CDialog
{
CResizeCtrl m_resize;
In OnInitDialog
add the controls, that should be resized to the CResizeCtrl
object
BOOL CDemoDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_resize.Create( this );
m_resize.Add( IDC_EDIT1, 0, 0, 100, 50 );
m_resize.Add( IDC_LIST1, 0, 50, 100, 50 );
m_resize.Add( IDOK, 50, 100, 0, 0 );
m_resize.SetMinimumTrackingSize();
or
BOOL CDemoDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_resize.Create( this );
CResizeInfo rInfo[] =
{
{ IDC_EDIT1, 0, 0, 100, 50 },
{ IDC_LIST1, 0, 50, 100, 50 },
{ IDOK, 50, 100, 0, 0 },
{ 0 },
};
m_resize.Add( rInfo );
m_resize.SetMinimumTrackingSize();
Because CResizeCtrl
is not a derived class from CDialog
, it can be used without changing the dialog template.
It can even be used with the common controls. The demo project includes an example, how to use it with GetOpenFileName
.