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

如题,前一阵子为它“清减”了,还好在死了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
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值