OnSize中等比例缩放控件大小

在OnInitDialog中初始化OldPoint

    CRect rect;
    GetClientRect(&rect);
    oldPiont.x = rect.right - rect.left;
    oldPiont.y = rect.bottom - rect.top;

在Onsize中更改比例

    //等比例缩放所有的元素
    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 / oldPiont.x;
    fsp[1] = (float)newPoint.y / oldPiont.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);
}
oldPiont = newPoint;
return;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容