调整窗口尺寸

#include "stdafx.h" BOOL Zoom_Window(HWND hWnd, LPRECT lpTargetRect, LPRECT mOrgRect, BOOL bZoomEx_Only) { if(hWnd) { CRect TaregetEX_Pos = lpTargetRect; BOOL IsVisable = IsWindowVisible(hWnd); //保持可见状态 ::SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_HIDEWINDOW); //隐藏窗口 if(!bZoomEx_Only) { CRect SrcWndRect; if(mOrgRect) { SrcWndRect = mOrgRect; } else { GetWindowRect(hWnd,&SrcWndRect); } DWORD style = GetWindowLong(hWnd, GWL_STYLE); int 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); } } 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); }

你可能感兴趣的:(null,include,border)