I use a global RECT
to storage the left, top, width and height of Edit control(RECT editSize = { 100, 50 , 100, 100 }
) .
In WM_SIZE
message, call EnumChildWindows
, resize my child windows in EnumChildProc
case WM_SIZE:
GetClientRect(hWnd, &rcClient);
EnumChildWindows(hWnd, EnumChildProc, (LPARAM)&rcClient);
return 0;
EnumChildProc
:
#define ID_Edit1 200
...
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
int idChild;
idChild = GetWindowLong(hwndChild, GWL_ID);
LPRECT rcParent;
rcParent = (LPRECT)lParam;
if (idChild == ID_Edit1) {
//Calculate the change ratio
double cxRate = rcParent->right * 1.0 / 884; //884 is width of client area
double cyRate = rcParent->bottom * 1.0 / 641; //641 is height of client area
LONG newRight = editSize.left * cxRate;
LONG newTop = editSize.top * cyRate;
LONG newWidth = editSize.right * cxRate;
LONG newHeight = editSize.bottom * cyRate;
MoveWindow(hwndChild, newRight, newTop, newWidth, newHeight, TRUE);
// Make sure the child window is visible.
ShowWindow(hwndChild, SW_SHOW);
}
return TRUE;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…