MFC 中调用自定义类中的函数实现框架的最大化解决思路
MFC 中调用自定义类中的函数实现框架的最大化
我定义了一个类,在类中有个方法实现:
void Cchangesize::control(int m_old_cx,int m_old_cy,int cx, int cy)
{
if (cx==0||cy==0)
{
cx=800;
cy=600;
}
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;
int ictrlid;
CWnd *pchile=GetWindow(GW_CHILD);
while (pchile)
{
ictrlid=pchile->GetDlgCtrlID();
pwnd=GetDlgItem(ictrlid);
pwnd->GetWindowRect(&wndrect);
ScreenToClient(&wndrect);
wndrect.right=(int)(wndrect.right*dx_percent);
wndrect.left=(int)(wndrect.left*dx_percent);
wndrect.bottom=(int)(wndrect.bottom*dy_percent);
wndrect.top=(int)(wndrect.top*dy_percent);
pwnd->MoveWindow(&wndrect);
pchile=pchile->GetWindow(GW_HWNDNEXT);
}
}
我在框架类中的onsize函数中调用这个方法,可是在最大化时就会中断(是框架类的函数就没问题)
------解决方案--------------------
我定义了一个类,在类中有个方法实现:
void Cchangesize::control(int m_old_cx,int m_old_cy,int cx, int cy)
{
if (cx==0||cy==0)
{
cx=800;
cy=600;
}
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;
int ictrlid;
CWnd *pchile=GetWindow(GW_CHILD);
while (pchile)
{
ictrlid=pchile->GetDlgCtrlID();
pwnd=GetDlgItem(ictrlid);
pwnd->GetWindowRect(&wndrect);
ScreenToClient(&wndrect);
wndrect.right=(int)(wndrect.right*dx_percent);
wndrect.left=(int)(wndrect.left*dx_percent);
wndrect.bottom=(int)(wndrect.bottom*dy_percent);
wndrect.top=(int)(wndrect.top*dy_percent);
pwnd->MoveWindow(&wndrect);
pchile=pchile->GetWindow(GW_HWNDNEXT);
}
}
我在框架类中的onsize函数中调用这个方法,可是在最大化时就会中断(是框架类的函数就没问题)
------解决方案--------------------