您的位置:首页 > 其它

按分辨率不同调整对话框大小以及控件大小

2012-06-06 15:31 225 查看
如题,前一阵子为它“清减”了,还好在死了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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: