- 将对话框Border:修改为Resizing模式
- 定义变量:CRect m_DlgRect; //用于保存原对话框大小
CRect m_DlgRect;
- 在初始化函数中添加:GetClientRect(&m_DlgRect); //获取对话框的大小
BOOL CControlDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
GetClientRect(&m_DlgRect);
return TRUE;
}
afx_msg void OnSize(UINT nType, int cx, int cy);
BEGIN_MESSAGE_MAP(CControlDlg, CDialogEx)
ON_WM_SIZE()
END_MESSAGE_MAP()
void CControlDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
CWnd *pWnd = NULL;
pWnd = GetDlgItem(IDC_LIST);
if (nType == SIZE_MINIMIZED)
return;
if (pWnd)
{
CRect rect;
LONG cWidth, cHeight;
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.left = rect.left * cx / m_DlgRect.Width();
rect.top = rect.top * cy / m_DlgRect.Height();
rect.bottom = cy - rect.top - 27;
rect.right = cx - rect.top - rect.left;
pWnd->MoveWindow(rect);
CWnd *pOkWnd, *pCancelWnd;
pOkWnd = GetDlgItem(IDOK);
pCancelWnd = GetDlgItem(IDCANCEL);
CRect okRect, cancelRect;
pOkWnd->GetWindowRect(&okRect);
ScreenToClient(&okRect);
pOkWnd->SetWindowPos(NULL, okRect.left, rect.bottom + 5, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
pCancelWnd->GetWindowRect(&cancelRect);
ScreenToClient(&cancelRect);
pCancelWnd->SetWindowPos(NULL, rect.right - cancelRect.right + cancelRect.left, rect.bottom + 5, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
GetClientRect(&m_DlgRect);
}