OnSize 改变控件的大小

来源:互联网 发布:网络前沿技术有哪些 编辑:程序博客网 时间:2024/06/06 06:44

重载

OnSize

函数

 

声明:

afx_msg

void

OnSize(UINT nType, 

int

 cx, 

int

 cy);

//

调整控件大小

 

 

//

调整控件大小

 

void CZTCServerDlg::OnSize(UINT nType, int cx, int cy) 

 

CDialogEx::OnSize(nType, cx, cy); 

 

CWnd 

 

 

*pCtrl=this->GetWindow(GW_CHILD); 

 

 

while(pCtrl&&nType!=1) //

判断是否为空,

因为对话框创建时会调用此函数,

而当

时控件还未创建

 

 

 

 

CRectrect; 

 

 

//

获取控件变化前大小

 

 

 

pCtrl->GetWindowRect(&rect); //

得到主窗口的大小

 

 

 

ScreenToClient(&rect);//

将控件大小转换为在对话框中的区域坐标

 

 

 

if (m_rect.Width() == 0) { 

 

 

 

break; 

 

 

 

 

rect.left=rect.left*cx/m_rect.Width();//

调整控件大小

 

 

 

rect.right=rect.right*cx/m_rect.Width(); 

 

 

rect.top=rect.top*cy/m_rect.Height(); 

 

 

rect.bottom=rect.bottom*cy/m_rect.Height(); 

 

 

pCtrl->MoveWindow(rect);//

设置控件大小

 

 

 

pCtrl=pCtrl->GetNextWindow(); 

 

 

 

GetClientRect(&m_rect);//

将变化后的对话框大小设为旧大小

 

}

0 0