15,979
社区成员
发帖
与我相关
我的任务
分享
void CNetTestDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
CRect rect,rectstatic;
CWnd *pWnd,*pWndStatic;
pWndStatic = GetDlgItem(IDC_STATIC_IP);
pWnd = GetDlgItem(IDC_IPADDRESS1);
if(pWnd && pWndStatic)
{
pWnd->GetWindowRect(&rect); //得到原窗口的大小
pWndStatic->GetWindowRect(&rectstatic);
ScreenToClient(&rect);
ScreenToClient(&rectstatic); //将控件大小转换为在对话框中的区域坐标
rect.left = rect.left * cx / m_rect.Width(); //cx / m_rect.Width()为横向变化比例
rect.right = rect.right * cx / m_rect.Width();
rect.bottom = rect.bottom * cy / m_rect.Height(); //cy / m_rect.Height()为纵向变化比例
rect.top = rect.top * cy / m_rect.Height();
rectstatic.left = rectstatic.left * cx / m_rect.Width();
rectstatic.right = rectstatic.right * cx / m_rect.Width();
rectstatic.bottom = rectstatic.bottom * cy / m_rect.Height();
rectstatic.top = rectstatic.top * cy / m_rect.Height();
pWnd->MoveWindow(rect);
pWndStatic->MoveWindow(rectstatic);
}
GetClientRect(&m_rect);//将变化后的对话框大小设为旧大小
}