由于功能的需要,需要动态更改对话框的大小及位置,直接上代码,大家可以看一下。
//增加
void CResizedlgDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CRect rect;
GetWindowRect(rect);
int width=rect.Width();
int height=rect.Height();
CString strOldSize;
strOldSize.Format(_T("width:%d,height:%d"),width,height);
//AfxMessageBox(strOldSize);
width+=100;
height+=100;
int cx = GetSystemMetrics(SM_CXSCREEN); //屏幕宽度
int cy = GetSystemMetrics(SM_CYSCREEN); //屏幕高度
int iLeft=(cx-width)/2;
int iTop=(cy-height)/2;
//移动
MoveWindow(iLeft, iTop, width, height);
}
//减小
void CResizedlgDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CRect rect;
GetWindowRect(rect);
int width=rect.Width();
int height=rect.Height();
CString strOldSize;
strOldSize.Format(_T("width:%d,height:%d"),width,height);
//AfxMessageBox(strOldSize);
width-=100;
height-=100;
int cx = GetSystemMetrics(SM_CXSCREEN); //屏幕宽度
int cy = GetSystemMetrics(SM_CYSCREEN); //屏幕高度
int iLeft=(cx-width)/2;
int iTop=(cy-height)/2;
//移动
MoveWindow(iLeft, iTop, width, height);
}