GetXXX -> ReleaseObject
这段英文的意思是:在销毁对象之前,要先把对象从DC中选出(否则DeleteObject会失败)。
CClientDC 之类的东西,在其析构函数释放资源
而CBrush,CPen,CFont,却没有,需要显示释放,你可以自己做一个类,比如 CAutoFont,也在析构里面释放资源,不过感觉也没有感到好用
Create ,要有 Delete
4.CPen
Get, 要有 Release
所以希望大牛们说说在ONPaint或ONDraw响应函数中定义了局部MFC GdiObject类对象(如CBrush,CPen,CFont,CBitmap),绘图完成并恢复了旧的(CBrush,CPen,CFont,CBitmap)对象后,我是否还必须要调用局部对象.DeleteObject(); 来释放资源?
一直都没注意过这个问题啊。
这些类都可以参看到源码,自己看一下就清楚了;GDI类关键是不要占用其资源,就都可以自己管理好GDI资源。
mark
一下下
//绘制一些文字
还是有两点疑惑:
1.好象只可以看到CBrush的头文件AFXWIN.H,我在VC6.0中的实现文件AFXWIN.CPP没找不到CBrush的实现部分.不知道怎么才能
看CBrush类的实现源码
2.MSDN中确实也没有说这些类需要自己调用 局部对象.DeleteObject(); 来释放资源(一般如果确实必须要调用局部对象.DeleteObject(); 来自己释放资源的话MSDN都会很明确的指出),但不知道为什么好几个比较权威比较流行的视频教学或书籍及其例子中在ONPaint或ONDraw响应函数返回前都添加了 局部对象.DeleteObject();来释放资源.
Create ,要有 Delete
Get, 要有 Release
的,
给分满24小时后再加100分,盼此一帖能解惑
1,查看vc安装目录中的mfc代码
2. 一样的需要DeleteObject
已经说了,不需要,但是一定要从DC中选出GDI对象
1、首先安装VC时要安装源代码,调试程序时可以用F11跟踪到MFC的源代码里面。cfont类
学习了!谢谢
再次查看了手头的资料发现它们只是在创建了CFont对象并使用完后才会手动添加局部对象.DeleteObject();来
释放资源,经查MSDN发现:1.CFont
When you finish with the CFont object created by the CreateFontIndirect function, first select the font out of the device context, then delete the CFont object.
When you finish with the CFont object created by the CreateFont function, first select the font out of the device context, then delete the CFont object.
When you finish with the CFont object created by the CreatePointFont function, first select the font out of the device context, then delete the CFont object.
When you finish with the CFont object created by the CreatePointFontIndirect function, first select the font out of the device context, then delete the CFont object.
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-32942-1.html
烊烊