#include "stdafx.h"
#include "dlg_resize.h"
/////////////////////////////////////////////////////////////////////////
// default constructor
CResizeControl::CResizeControl( void )
: m_hParent( NULL )
, m_hControl( NULL )
, m_bLeftAnchor( false )
, m_bRightAnchor( false )
, m_bTopAnchor( false )
, m_bBottomAnchor( false )
{
};
//////////////////////////////////////////////////////////////////////////
// constructor init members by control window handler and align type
CResizeControl::CResizeControl( HWND hControl, long Align )
: m_hParent( NULL )
, m_hControl( NULL )
, m_bLeftAnchor( false )
, m_bRightAnchor( false )
, m_bTopAnchor( false )
, m_bBottomAnchor( false )
{
SetControl( hControl );
SetAlign( Align );
};
//////////////////////////////////////////////////////////////////////////
// constructor init members by control window handler and align type
CResizeControl::CResizeControl( HWND hParent, int CtrlID, long Align )
: m_hParent( NULL )
, m_hControl( NULL )
, m_bLeftAnchor( false )
, m_bRightAnchor( false )
, m_bTopAnchor( false )
, m_bBottomAnchor( false )
{
SetControl( hParent, CtrlID );
SetAlign( Align );
};
//////////////////////////////////////////////////////////////////////////
// Function store in class members all needed to resize info
void CResizeControl::SetControl( HWND hControl )
{
m_hControl = hControl;
m_hParent = ::GetParent( m_hControl );
RECT tRect;
POINT tPoint;
::GetWindowRect( m_hControl, &tRect );
::GetClientRect( m_hParent, &m_tParent );
// Get client coordinates (left, top)
tPoint.x = tRect.left;
tPoint.y = tRect.top;
::ScreenToClient( m_hParent, &tPoint );
m_tClient.left = tPoint.x;
m_tClient.top = tPoint.y;
// Get client coordinates (right, bottom)
tPoint.x = tRect.right;
tPoint.y = tRect.bottom;
::ScreenToClient( m_hParent, &tPoint );
m_tClient.right = tPoint.x;
m_tClient.bottom = tPoint.y;
};
//////////////////////////////////////////////////////////////////////////
// function will update size and position of control
void CResizeControl::UpdatePos( HDWP hDef /*= NULL*/ )
{
int x = 0, y = 0;
int cx = m_tClient.right - m_tClient.left;
int cy = m_tClient.bottom - m_tClient.top;
RECT tParent;
::GetClientRect( m_hParent, &tParent );
if( m_bLeftAnchor )
{
x = m_tClient.left;
if( m_bRightAnchor )
cx = tParent.right - x - ( m_tParent.right - m_tClient.right );
}
else
if( m_bRightAnchor )
x = tParent.right - cx - ( m_tParent.right - m_tClient.right );
if( m_bTopAnchor )
{
y = m_tClient.top;
if( m_bBottomAnchor )
cy = tParent.bottom - y - ( m_tParent.bottom - m_tClient.bottom );
}
else
if( m_bBottomAnchor )
y = tParent.bottom - cy - ( m_tParent.bottom - m_tClient.bottom );
if( hDef )
::DeferWindowPos( hDef, m_hControl, NULL, x, y, cx, cy, SWP_NOZORDER | SWP_NOOWNERZORDER );
else
::SetWindowPos( m_hControl, NULL, x, y, cx, cy, SWP_NOZORDER | SWP_NOOWNERZORDER );
};
//:> end of file