怎样让CFormView中的控件随着View大小的改变而比例改变?
1个回答
展开全部
已经搞定,共享之:
视类中加成员函数和成员变量:
void SetControlInfo(WORD CtrlId);protected:int m_old_cx,m_old_cy;
CDWordArray m_control_info;
构造函数中初始化:
m_old_cx = m_old_cy = 0;
加控件信息的函数定义:
void CTestFormView::SetControlInfo(WORD CtrlId){m_control_info.Add(CtrlId);}
修改OnSize函数:
void CTestFormView::OnSize(UINT nType, int cx, int cy){if(cx==0 || cy==0){cx=800;cy=600;}CFormView::OnSize(nType, cx, cy);
float dx_percent = (m_old_cx ==0)? 1 : (float)((float)cx/(float)m_old_cx);
float dy_percent = (m_old_cy ==0)? 1 : (float)((float)cy/(float)m_old_cy);
if(m_old_cx){CRect WndRect;
CWnd *pWnd;
for(int i = 0; i < m_control_info.GetSize(); i++){pWnd = GetDlgItem(m_control_info[i]);if(!pWnd){TRACE("Control ID - %d NOT FOUND!!\n",m_control_info[i]);continue;}
pWnd-GetWindowRect(&WndRect);
ScreenToClient(&WndRect);
WndRect.left = (int)(WndRect.left*dx_percent);
WndRect.right = (int)(WndRect.right* dx_percent);
WndRect.bottom = (int)(WndRect.bottom*dy_percent);
WndRect.top = (int)(WndRect.top*dy_percent);
pWnd-MoveWindow(&WndRect);}}m_old_cx = cx;
m_old_cy = cy;}
在OnInitialUpdate函数中加入控件ID:
SetControlInfo(IDC_BUTTON1);
。。。。。。。。。。。。。。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询