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

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

  • 相关阅读:
    String前后去掉空格、option只能定义value值吗?还能添加什么值。dom和Jquery对象转换。
    JsonObject没有fromObject、idea引入maven有红线没依赖、JsonObject maven 依赖包
    json几个小例子
    [极客大挑战 2019]PHP1
    栈溢出原理笔记(一)
    CentOS7怎么安装图形界面
    快速搭建WordPress博客
    Mac 安装Mysql 之 Sqlservice 区别
    Metasploit-初篇
    Windows To Go 制作详解
  • 原文地址:https://www.cnblogs.com/personnel/p/14260887.html
Copyright © 2011-2022 走看看