zoukankan      html  css  js  c++  java
  • ReleaseDC 和 DeleteDC 的区别

    简单的说,GetDCReleaseDC 的调用配对,CreateDCDeleteDC 的调用配对。

    GetDC 是从窗口获取现有的 DC,而 CreateDC 是创建 DC,所以 ReleaseDC 和 DeleteDC 的作用一个是释放,一个是销毁。

    叁考:https://blog.csdn.net/business122/article/details/9612299

    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 释放

    这样就不会出现内存泄露事情了

  • 相关阅读:
    python 学习——sqlalchemy 模块
    python学习——数据库基本知识mysql
    算法设计22——并行算法2 实际应用中的优化
    Perl 学习
    python学习——装饰器、生成器、迭代器
    算法设计19—— 全对最短路径 Floyd算法
    asp.net Core 使用过滤器判断请求客户端是否为移动端,并实现PC端和移动端请求映射和自动跳转
    在windows平台使用Apache James搭建邮件服务器以及使用C#向外网发送邮件
    asp.net core3.1策略授权问题
    Unity调用安卓中的方法遇到的问题
  • 原文地址:https://www.cnblogs.com/personnel/p/14260887.html
Copyright © 2011-2022 走看看