修改对话框尺寸后,保持其内的CComboBox和CEdit也同步尺寸,开始使用的是GetWindowRect()函数得倒一个Rect,在使用MoveWindow()函数修改CComboBox和CEdit的尺寸,发现CComboBox的下拉列表比例明显失调,虽小后尺寸也和扩大前不同。因此,后来改用GetClientRect()函数和SetWindowPos()函数,发现这样的话,尺寸比例保持的非常完美。代码如下:
void CChap4ProcessInfoDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(!IsWindowVisible())
return;
else {
RECT rc_combobox;
CComboBox* pcbb = (CComboBox*)GetDlgItem(IDC_CBB);
pcbb->GetClientRect(&rc_combobox);
pcbb->SetWindowPos(NULL, 0, 0, cx, rc_combobox.bottom, SWP_NOZORDER);
RECT rc_edit;
CEdit* pe = (CEdit*)GetDlgItem(IDC_EDIT);
pe->GetClientRect(&rc_edit);
pe->SetWindowPos(NULL, 0, rc_combobox.bottom, cx, cy-rc_combobox.bottom, SWP_NOZORDER);
}
return;
}