int nCount=listRect.GetCount();
if(listRect.GetCount()>0)
{
CRect rectDlgNow;
m_pWnd->GetWindowRect(&rectDlgNow);
POSITION mP = listRect.GetHeadPosition();
CRect rectDlgSaved;
rectDlgSaved = listRect.GetNext(mP);
m_pWnd->ScreenToClient(rectDlgSaved);
m_pWnd->ScreenToClient(rectDlgNow);
float fRateScaleX = (float)(rectDlgNow.right-rectDlgNow.left)/(rectDlgSaved.right-rectDlgSaved.left);
float fRateScaleY = (float)(rectDlgNow.bottom-rectDlgNow.top)/(rectDlgSaved.bottom-rectDlgSaved.top);
m_pWnd->ClientToScreen(rectDlgSaved);
m_pWnd->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;//这是别人写的程序,我下载下来参考。他此处new了一个,但是往下没有delete
//运行这个程序之后系统总是无缘无故随机蓝屏,我怀疑是这个new没有delete。
m_pCFont->CreateFontIndirect(&stFont); CRect rectChildSaved;
CWnd *pWndChild = m_pWnd->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);
m_pWnd->ScreenToClient(rectChildSaved);
pWndChild->MoveWindow(rectChildSaved); pWndChild->SetFont(m_pCFont); pWndChild = pWndChild->GetNextWindow();
}
delete m_pCFont;//我在此处加了一个delete,但是程序运行后字体变成粗体了,不是以前对话框刚创建时的那样~
//如果不加这个delete字体倒是比较正常,
//请问我到底该加不加这个delete?加在什么位置?加载之后字体变得粗体了怎么办?
}
解决方案 »
- 在unicode字符集下 CTIME 转CString 日期可以用但是时间有问题?
- 字体的宽度不一怎么办?
- 关于SetDefaultCharFormat(m_CharFormat2);
- 难题(用代码实现在ACTIVEX容器中插入对象)
- 做过windows media encoding sdk 开发的请进
- 菜鸟一问:在窗口大小改变是如何才能改变控件的位置和大小?
- ★★★如何将CString strInfo=“0x30313233343536373839” 转换成二进制串到char * pMsgInfo。
- 请提供密码编码学与网络安全:原理与实践(第二版) William Stallings的电子版下载地址
- 关于pRst->Close()和pRst.Release()
- 数值的格式化输出
- 关于对话框处理函数中的全局变量的问题
- VS2008 调试问题!很纠结!!
看看有没有资源泄漏
如果多次new,设计有问题
呵呵~我找了~没有~
原来2010直接就可以检测内存泄露~~检测我上面的代码后有这个提示Detected memory leaks!
Dumping objects ->
d:\users\ww\desktop\dialogex\dialogex\1 (4).net\dialogex - 副本\dialogex.cpp(116) : {498} client block at 0x0008A610, subtype c0, 8 bytes long.
a CFont object at $0008A610, 8 bytes long
Object dump complete.就是说m_pCFont = new CFont;这句存在泄露~~我把delete m_pCFont放在析构函数中还不行啊~还提示泄露~
就像这样:
http://support.microsoft.com/kb/85518/zh-cn