void CserialcommunicationDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
// TODO: 在此处添加消息处理程序代码
if (nType == SIZE_RESTORED || nType == SIZE_MAXIMIZED)
{
Resize();
}
}
void CserialcommunicationDlg::Resize(void)
{
float fsp[2];
POINT newPoint;//获取当前对话框大小
CRect newRect;//获取当前对话框的坐标
GetClientRect(&newRect);
newPoint.x = newRect.right - newRect.left;
newPoint.y = newRect.bottom - newRect.top;
fsp[0] = (float)newPoint.x / Old.x;
fsp[1] = (float)newPoint.y / Old.y;
int woc;
CRect rect;
CPoint oldTLPoint, newTLPoint;//左上角
CPoint oldBRPoint, newBRPoint;//右下角
//列出所有的子空间
HWND hwndChild = ::GetWindow(m_hWnd, GW_CHILD);
while (hwndChild) {
woc = ::GetDlgCtrlID(hwndChild);//取得ID
GetDlgItem(woc)->GetWindowRect(rect);
ScreenToClient(rect);
oldTLPoint = rect.TopLeft();
newTLPoint.x = long(oldTLPoint.x*fsp[0]);
newTLPoint.y = long(oldTLPoint.y*fsp[1]);
oldBRPoint = rect.BottomRight();
newBRPoint.x = long(oldBRPoint.x*fsp[0]);
newBRPoint.y = long(oldBRPoint.y*fsp[1]);
rect.SetRect(newTLPoint, newBRPoint);
GetDlgItem(woc)->MoveWindow(rect, TRUE);
hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT);
}
Old = newPoint;
return;
}
初始化代码:
CRect rect2;
GetClientRect(&rect2); //取客户区大小
Old.x = rect2.right - rect2.left;
Old.y = rect2.bottom - rect2.top;
//int cx = GetSystemMetrics(SM_CXFULLSCREEN);
//int cy = GetSystemMetrics(SM_CYFULLSCREEN);
//CRect rt;
//SystemParametersInfo(SPI_GETWORKAREA, 0, &rt, 0);
//cy = rt.bottom;
//MoveWindow(0, 0, cx, cy);