CFont.CreateFontIndirect can support Del

  • jianjun wang

    jianjun wang - 2012-03-20

    CFont.CreateFontIndirect  can support Del by otherway? for example deleobject(CFont) instead of CFont.Deleobject()?
    such case may cause destruction problem.

  • David

    David - 2014-01-27


    Normally we don't need to manually delete the HFONT assigned to a CFont object. Win32++ automatically deletes the HFONT for us when the CFont is deconstructed, or when a different font is assigned to the CFont, such as via CFont.CreateFontIndirect.

    As you mentioned, we can also use CFont::DeleteObject to manually delete the HFONT assigned to a CFont. It doesn't matter whether or not the HFONT is deleted from the CFont before it is deconstructed. No GDI resource is leaked, either way.

    We can also choose to detach the HFONT from the CFont. If we choose to do that, we are then responsible for deleting the HFONT when we are finished with it.

    There is no "destruction problem" I'm aware of in CFont. If you are experiencing problems with the destruction of a CFont, perhaps you could elaborate.

    Best regards,


Log in to post a comment.