BOOL Zoom_Window(HWND hWnd, CRect TaregetEX_Pos, LPRECT mOrgRect=NULL, BOOL bZoomEx_Only=FALSE)
{
if(hWnd)
{
BOOL IsVisable = IsWindowVisible(hWnd);
if(!bZoomEx_Only)
{
::SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_HIDEWINDOW);
CRect SrcWndRect;
if(mOrgRect)
{
SrcWndRect = mOrgRect;
}
else
{
GetWindowRect(hWnd,&SrcWndRect);
}
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
INT_PTR Board_dx = 0, Board_dy = 0;
if( WS_CAPTION == (style & WS_CAPTION) )
{
Board_dy += GetSystemMetrics(SM_CYCAPTION);
}
if( WS_DLGFRAME == (style & WS_DLGFRAME) )
{
Board_dx += 2 * GetSystemMetrics(SM_CXBORDER);
Board_dy += 2 * GetSystemMetrics(SM_CYBORDER);
}
else if( WS_BORDER == (style & WS_BORDER) )
{
Board_dx += GetSystemMetrics(SM_CXBORDER);
Board_dy += GetSystemMetrics(SM_CYBORDER);
}
else
{
}
double dx = (double)(TaregetEX_Pos.Width() - Board_dx) / (double)(SrcWndRect.Width() - Board_dx);
double dy = (double)(TaregetEX_Pos.Height() - Board_dy) / (double)(SrcWndRect.Height() - Board_dy);
HWND hChild = ::GetWindow(hWnd, GW_CHILD);
while(hChild != NULL)
{
CRect rect;
GetWindowRect(hChild, &rect);
CPoint pt_lt(rect.left, rect.top);
ScreenToClient(hWnd, &pt_lt);
MoveWindow(hChild,
(INT)(pt_lt.x * dx),
(INT)(pt_lt.y * dy),
(INT)(rect.Width() * dx),
(INT)(rect.Height() * dy), true);
hChild = GetWindow(hChild, GW_HWNDNEXT);
}
}
//MoveWindow(hWnd, TaregetEX_Pos.left, TaregetEX_Pos.top, TaregetEX_Pos.right, TaregetEX_Pos.bottom, true);
UINT nFlage = SWP_NOZORDER|SWP_DRAWFRAME|SWP_DEFERERASE;
if(IsVisable) nFlage |= SWP_SHOWWINDOW;
::SetWindowPos(hWnd, 0,
TaregetEX_Pos.left, TaregetEX_Pos.top, TaregetEX_Pos.Width(), TaregetEX_Pos.Height(),
nFlage);
}
return(false);
}
//应用
CCCCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
Zoom_Window(GetSafeHwnd(),
CRect(0,0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)) );
……
}