2.CBitmap
You can use the CGdiObject::DeleteObject function to delete bitmap loaded by the LoadBitmap function, or the CBitmap destructord pattern and color. The brush can subsequently be selected as the current brush for any device context.
结合你的代码,CreateCaret创建提示符 虽然没有明确使用资源的是什么对象 但是去MSDN上就可以知道了 实际上使用提示符的是CTextView这个窗口
CPen::CPen() If you use the constructor with no arguments, you must initialize the resulting CPen object with the CreatePen, CreatePenIndirect, or CreateStockObject member functions. If you use the constructor that takes arguments, then no further initialization is necessary. The constructor with arguments can throw an exception if errors are encountered, while the constructor with no arguments will always succeed.
CPen::CreatePen() When an application no longer requires a given pen, it should call the CGdiObject::DeleteObject member function or destroy the CPen object so the resource is no longer in use. An application should not delete a pen when the pen is selected in a device context.
感谢大牛们指导!!!加分后结帖
CFont也是从CGdiObject类派生的,析构时会自动DeleteObject。
我觉得会出现你所说的那种情况主要跟 使用资源的对象和对象使用资源的方式有关系。
//那CBrush,CPen,CFont的对象则必须手动添加 对象名.DeleteObject();
1.使用资源的对象可分为两类 局部和全局
2.使用资源的方式也分为两类 拷贝和指针
,是一个全局的对象。但是它使用资源的方式却可以认为是指针式的 即它在使用bitmap作为提示符时 其实并没有把bitmap拷贝一份 而是“寄希望于”它一直存在。这样 当你的bitmap是局部变量的时候 它就找不到这个资源了 也就没法显示提示符了。
但是当CDC* pDC; 使用CBrush,CPen,CFont时,pDC所指向的CDC是全局的 但是它使用资源的方式可以认为是拷贝式的 也就是当我们建立一个CPen pen; 并执行pDC->SelectObject(&pen);后,实际上相当于将pen拷贝了一份给CDC。cfont类这样 就算是pen是局部变量 在以后的使用过程中也会保持pen所代表的画笔。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-32942-2.html
我需要输入登录名个密码的wifi
梦一场