网上下的关于对话框缩放,但是运行后系统总是不定时蓝屏,估计是有什么没被释放~请详细帮我解释一下这段代码的思路!!谢谢!!//全局变量
typedef CMap<CString, LPCSTR, CRect, CRect&> CMapCStringToCRect;
typedef CList<CRect, CRect> CListRect;
typedef struct _SCREEN
{
int nScreenX;
int nScreenY;
}SCREEN;
//头文件中定义
CMapCStringToCRect mapStrToRect;
CListRect listRect;
SCREEN screen;
BOOL CDialogExDlg::OnInitDialog()
{
         CRect rectWnd;
GetWindowRect(&rectWnd);
listRect.AddTail(&rectWnd);
CWnd *pWndChild = GetWindow(GW_CHILD);
while(pWndChild)
{
pWndChild->GetWindowRect(&rectWnd);
listRect.AddTail(&rectWnd);
pWndChild = pWndChild->GetNextWindow();
}
}
void CDialogExDlg::OnSize(UINT nType, int cx, int cy) 
{
int nCount=listRect.GetCount();
if(listRect.GetCount()>0)
{
CRect rectDlgNow;
GetWindowRect(&rectDlgNow);
POSITION mP = listRect.GetHeadPosition();
CRect rectDlgSaved;
rectDlgSaved = listRect.GetNext(mP);
ScreenToClient(rectDlgSaved);
ScreenToClient(rectDlgNow);
float fRateScaleX = (float)(rectDlgNow.right-rectDlgNow.left)/(rectDlgSaved.right-rectDlgSaved.left);
float fRateScaleY = (float)(rectDlgNow.bottom-rectDlgNow.top)/(rectDlgSaved.bottom-rectDlgSaved.top);
ClientToScreen(rectDlgSaved);
ClientToScreen(rectDlgNow);
LOGFONT stFont;
::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT), sizeof(stFont), &stFont);
strcpy(stFont.lfFaceName,"Times New Roman");
stFont.lfHeight = (long)(fRateScaleY*14);
stFont.lfWidth = (long)(fRateScaleX*7);
CFont * m_pCFont;
m_pCFont = new CFont;
m_pCFont->CreateFontIndirect(&stFont);
CRect rectChildSaved;
CWnd *pWndChild = GetWindow(GW_CHILD);
while(pWndChild)
{
rectChildSaved = listRect.GetNext(mP);
rectChildSaved.left = rectDlgNow.left+(int)((rectChildSaved.left-rectDlgSaved.left)* fRateScaleX);
rectChildSaved.top = rectDlgNow.top+(int)((rectChildSaved.top-rectDlgSaved.top)*fRateScaleY);
rectChildSaved.right = rectDlgNow.right+(int)((rectChildSaved.right-rectDlgSaved.right)* fRateScaleX);
rectChildSaved.bottom = rectDlgNow.bottom+(int)((rectChildSaved.bottom-rectDlgSaved.bottom)* fRateScaleY);
ScreenToClient(rectChildSaved);
pWndChild->MoveWindow(rectChildSaved);
pWndChild->SetFont(m_pCFont);
pWndChild = pWndChild->GetNextWindow();
}
}
Invalidate();
}

解决方案 »

  1.   

    蓝屏一般都是驱动的原因吧,光是UI应用程序能够写得来把NT搞蓝屏的好像还没有
      

  2.   

    解释一下思路嘛~我看他也没有说设置哪个控件的缩放,运行时整个窗口里的控件都跟着缩放了,包括我在picture控件~~
      

  3.   

    初始化函数中遍历所有的子窗口(控件),将控件的Rect放入链表
    OnSize中又将这些rect全部从链表中取出,缩放(fRateScaleX),然后计算出新的rect大小,MoveWindow实现控件大小的缩放