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

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

  • 相关阅读:
    pptpvpn链接问题
    nginx网站架构优化思路(原)
    KEEPALIVED 检测RS原理
    linux 做gw(nat)详细配置
    pptpvpn 连接后 无法上外网
    网站最常见的错误
    Python服务器开发 -- 网络基础
    python高性能编程方法一
    一步步来用C语言来写python扩展
    http响应Last-Modified和ETag
  • 原文地址:https://www.cnblogs.com/personnel/p/14260887.html
Copyright © 2011-2022 走看看