VC比例放大缩小
CRect rect; ::GetWindowRect(m_hWnd, rect); ScreenToClient(rect); m_nDlgWidth = rect.right - rect.left; m_nDlgHeight = rect.bottom - rect.top; //计算分辨率 m_nWidth = GetSystemMetrics(SM_CXSCREEN); m_nHeight = GetSystemMetrics(SM_CYSCREEN); //计算放大倍数 m_Multiple_width = float(m_nWidth)/float(m_nDlgWidth); m_Multiple_height = float(m_nHeight)/float(m_nDlgHeight); change_flag = TRUE;//判断onSize执行时OnInitDlg是否已执行 MoveWindow(0,0,m_nWidth,m_nHeight, TRUE);
void CTDemoDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); if (change_flag) { ReSize(IDC_BUTTON); ReSize(IDOK); ReSize(IDCANCEL); //恢复放大倍数,并保存 m_Multiple_height = float(1)/m_Multiple_height; m_Multiple_width = float(1)/m_Multiple_width; } } void CTDemoDlg::ReSize(int nID) { CRect rect; GetDlgItem(nID)->GetWindowRect(rect); ScreenToClient(rect); //计算控件左上角点 CPoint OldTLPoint, TLPoint; OldTLPoint = rect.TopLeft(); TLPoint.x = long(OldTLPoint.x*m_Multiple_width); TLPoint.y = long(OldTLPoint.y*m_Multiple_height); //计算控件右下角点 CPoint OldBRPoint,BRPoint; OldBRPoint = rect.BottomRight(); BRPoint.x = long(OldBRPoint.x*m_Multiple_width); BRPoint.y = long(OldBRPoint.y*m_Multiple_height); //移动控件到新矩形 rect.SetRect(TLPoint,BRPoint); GetDlgItem(nID)->MoveWindow(rect, TRUE); }