ReleaseDC和DeleteDC的区别
来源:互联网 发布:2016淘宝618大促报名 编辑:程序博客网 时间:2024/05/23 00:34
今天做一个小软件时需要在界面上重复绘制图形
于是写了个函数绘制图形
然后在OnPaint()里调用
发现低频率的重绘窗口还好 一旦经常重绘窗口就会出现错误
应该是内存泄露的错误
但是我发现我所有的CDC全都DeleteDC了 怎么会出现这错误了
于是查了下MSDN
在ReleaseDC里写着
API原文
intReleaseDC(CDC*pDC);
Return Value
Nonzero if successful; otherwise 0.
Parameters
pDC
Identifies the device context to be released.
Remarks
Releases a device context, freeing it for use by other applications. The effect of the ReleaseDCmember function depends on the device-context type.
The application must call the ReleaseDCmember function for each call to the member function and for each call to the member function.
这里最后一句提到了
The application must call the ReleaseDCmember function for each call to the member function and for each call to the member function.
所有调用GetWindowDC和GetDC获取的DC对象必须使用ReleaseDC来释放
然后又查看了DeleteDC的API内容
CDC::DeleteDC
virtualBOOLDeleteDC();
Return Value
Nonzero if the function completed successfully; otherwise 0.
Remarks
In general, do not call this function; the destructor will do it for you. The DeleteDCmember function deletes the Windows device contexts that are associated with m_hDCin the current CDCobject. If this CDCobject is the last active device context for a given device, the device is notified and all storage and system resources used by the device are released.
An application should not call DeleteDCif objects have been selected into the device context. Objects must first be selected out of the device context before it it is deleted.
An application must not delete a device context whose handle was obtained by calling . Instead, it must call to free the device context. The and classes are provided to wrap this functionality.
The DeleteDCfunction is generally used to delete device contexts created with , , or .
看了最后一句就可以区分什么时候调用ReleaseDC了
就是GetDC或GetWindowDC获得的DC要使用ReleaseDC释放
Create得到的DC要用Delete释放
、
这样就不会出现内存泄露事情了
- ReleaseDC和DeleteDC的区别
- ReleaseDC和DeleteDC的区别
- ReleaseDC和DeleteDC的区别
- releaseDC和deleteDC的区别
- ReleaseDC和DeleteDC的区别
- ReleaseDC 和DeleteDC的用法区别
- DeleteDC() ReleaseDC()和DeleteObject()之间的区别
- DeleteDC 与 ReleaseDC的区别
- DeleteDC ReleaseDC DeleteObject之间的区别
- deletedc和releasedc
- ReleaseDC、DeleteDC(买二送一DeleteObject)简单解析
- BeginPaint EndPaint 与GetDC ReleaseDC的区别
- BeginPaint EndPaint 与GetDC ReleaseDC的区别
- GetDC和ReleaseDC
- 内存泄漏,当您使用的 GetDC 方法和 ReleaseDC 方法 CWnd 类版本
- SelectObject,DeleteObject,DeleteDC的一些注释
- 行规——::GetDC()和::ReleaseDC()配对
- GetDC() ReleaseDC()引起的内存泄漏
- Invent Your Own Computer Games with Python 翻译(三)Strings
- platform详解
- 解决google map 卫星图层和电子地图图层偏移问题
- Overview of the High Efficiency Video Coding Standard——Inter-picture prediction(二)
- 单实例运行Java桌面应用程序
- ReleaseDC和DeleteDC的区别
- UISearchDisplayController UISearchBar
- poj2513
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(3)之 游戏主界面 -----武器系统---散花弹
- 对于大数
- iOS应用崩溃日志分析
- android使用外部文件管理获取文件路径
- 超级不错的web开发学习网站
- x86中的寄存器