CRect rect;
GetClientRect( &rect );
long r_Width = 0, r_Height = 0;
r_Width = rect.Width();
r_Height = rect.Height();
float ratio = 0, w_ratio = 0, h_ratio = 0;
float ratio = 0, w_ratio_pre = 0, h_ratio_pre = 0;
int nX = 0, nY = 0;
w_ratio_pre = (float) m_nWidth / (float) r_Width;
h_ratio_pre = (float) m_nHeight / (float) r_Height;
long v_WIdth = 0, v_Height = 0;
long v_Width_pre = 0, v_Height_pre = 0;
if ( r_Width < m_nWidth && r_Height <= m_nHeight )
{
if ( m_nWidth <= m_nHeight )
{
v_Height_pre = m_nHeight / h_ratio_pre;
v_Width_pre = m_nWidth / h_ratio_pre;
if ( r_Witdh < v_Width_pre )
{
w_ratio = (float) v_Width_pre / (float) r_Witdh;
v_Height = v_Height_pre / w_ratio;
v_WIdth = v_Width_pre / w_ratio;
}
else
{
v_Height = v_Height_pre;
v_WIdth = v_Width_pre;
}
}
else // if ( m_nWidth > m_nHeight )
{
v_Height_pre = m_nHeight / w_ratio_pre;
v_Width_pre = m_nWidth / w_ratio_pre;
if ( r_Height < v_Height_pre )
{
h_ratio = (float) v_Height_pre / (float) r_Height;
v_Height = v_Height_pre / h_ratio;
v_WIdth = v_Width_pre / h_ratio;
}
else
{
v_Height = v_Height_pre;
v_WIdth = v_Width_pre;
}
}
}
else if ( r_Width < m_nWidth && r_Height >= m_nHeight )
{
if ( m_nWidth <= m_nHeight )
{
v_Height_pre = m_nHeight / h_ratio_pre;
v_Width_pre = m_nWidth / h_ratio_pre;
if ( r_Witdh < v_Width_pre )
{
w_ratio = (float) v_Width_pre / (float) r_Witdh;
v_Height = v_Height_pre / w_ratio;
v_WIdth = v_Width_pre / w_ratio;
}
else
{
v_Height = v_Height_pre;
v_WIdth = v_Width_pre;
}
}
else // if ( m_nWidth > m_nHeight )
{
/*
v_Height_pre = m_nHeight / w_ratio_pre;
v_Width_pre = m_nWidth / w_ratio_pre;
if ( r_Height < v_Height_pre )
{
h_ratio = (float) v_Height_pre / (float) r_Height;
v_Height = v_Height_pre / h_ratio;
v_WIdth = v_Width_pre / h_ratio;
}
else
{
v_Height = v_Height_pre;
v_WIdth = v_Width_pre;
}
*/
v_Height = m_nHeight / w_ratio_pre;
v_WIdth = m_nWidth / w_ratio_pre;
}
}
else if ( r_Width > m_nWidth && r_Height <= m_nHeight )
{
if ( m_nWidth <= m_nHeight )
{
v_Height_pre = m_nHeight / h_ratio_pre;
v_Width_pre = m_nWidth / h_ratio_pre;
/*
if ( r_Witdh < v_Width_pre )
{
w_ratio = (float) v_Width_pre / (float) r_Witdh;
v_Height = v_Height_pre / w_ratio;
v_WIdth = v_Width_pre / w_ratio;
}
else
{
v_Height = v_Height_pre;
v_WIdth = v_Width_pre;
}
*/
v_Height = m_nHeight / h_ratio_pre;
v_WIdth = m_nWidth / h_ratio_pre;
}
else // if ( m_nWidth > m_nHeight )
{
v_Height_pre = m_nHeight / w_ratio_pre;
v_Width_pre = m_nWidth / w_ratio_pre;
if ( r_Height < v_Height_pre )
{
h_ratio = (float) v_Height_pre / (float) r_Height;
v_Height = v_Height_pre / h_ratio;
v_WIdth = v_Width_pre / h_ratio;
}
else
{
v_Height = v_Height_pre;
v_WIdth = v_Width_pre;
}
}
}
else if ( r_Width >= m_nWidth && r_Height >= m_nHeight )
{
v_Height = m_nHeight;
v_WIdth = m_nWidth;
}
nX = ( r_Width / 2 ) - ( v_Width / 2 );
nY = ( r_Height / 2 ) - ( v_Height / 2 );
아마도 PhotoCE를 만들 때 사용했던 루틴같다.