19,468
社区成员




void CELDlg::autosize(UINT nID,LPRECT lpRect)
{
CWnd *pWnd;
pWnd = GetDlgItem(nID); //获取控件句柄
if(!pWnd) return; //判断是否为空,因为对话框创建时会调用此函数,而当时控件还未创建
CRect rect,recttemp; //定义rect为控件变化后的参数
GetClientRect(&recttemp); //recttemp获取变化后对话框客户区大小
//计算各个参数值,利用每个值主窗口的相对值计算
rect.left = recttemp.Width() * lpRect->left/m_rectmin.Width();
rect.right = recttemp.Width() * lpRect->right/m_rectmin.Width();
rect.top = recttemp.Height() * lpRect->top/m_rectmin.Height();
rect.bottom = recttemp.Height() * lpRect->bottom/m_rectmin.Height();
pWnd->MoveWindow(rect);//调整控件位置
}