根据分辨率调整窗口
前一阵子在想实现按分辨率不同调整对话框大小以及控件大小的办法,为它“清减”了不少,还好在死了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
}
还有不小的问题,比如说在800*600下,字体大了点我只能把像按钮等一些要显示文字的控件弄大一点,标题栏的大小暂时没有解决,希望大家来讨论讨论,完善它!
posted on 2011-08-27 13:16 小楼-machine -vision 阅读(97) 评论(0) 收藏 举报