实现按分辨率不同调整对话框大小以及控件大小的办法!
如题,前一阵子为它“清减”了,还好在死了N次N亿个脑细胞后,在网上查找了海量的帖子之后,再加修改总算基本实现了。拿出来跟大家分享,满足一下虚荣心。呵呵!
int xxxDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CRect rc;
this->GetWindowRect(&rc);
int x,y;
float multiple,H;
//取得分辨率
x=GetSystemMetrics( SM_CXSCREEN );
y=GetSystemMetrics( SM_CYSCREEN );
multiple=(float)x/1024; //如果你布局时的分辨率不是1027*768,就改一下就行了。
H=(float)y/768;
//改变对话框的大小
this->MoveWindow((int)(rc.top*H),(int)(rc.left*multiple),(int)(rc.Width()*multiple),(int)(rc.Height()*H));
return 0;
}
BOOL XXXDlg::OnInitDialog()
{
CDialog::OnInitDialog();
.......................
int x,y;
float multiple,H;
int newx,newy,newwidth,newheight;
x=GetSystemMetrics( SM_CXSCREEN );
y=GetSystemMetrics( SM_CYSCREEN );
multiple=(float)x/1024;
H=(float)y/768;
CWnd *pWndChild=GetWindow(GW_CHILD);
while(pWndChild)
{
CRect rc;
pWndChild->GetWindowRect(&rc);
this->ScreenToClient(&rc);
newx=(int)(rc.left*multiple);
newy=(int)(rc.top*H);
newwidth=(int)(rc.Width()*multiple);
newheight=(int)(rc.Height()*H);
pWndChild->MoveWindow(newx,newy,newwidth,newheight);
pWndChild=pWndChild->GetNextWindow();
}
return TRUE; // return TRUE unless you set the focus to a control
}
字体的大小问题尚未解决,我只能把像按钮等一些要显示文字的控件弄大一点。希望对你有用!