CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    14

    How to destroy a CFont Object that I create

    Hello, All.
    For a CFont object that I create, I need to destroy the object when I am done using it. Otherwise will cause a space wasted. But what is the right way to destroy the object ?
    please see the following case:
    CFont NewFont;
    CFont *pOldFont;
    NewFont.CreateFont();
    pOldFont = pDC->SelectObject(&NewFont);
    ....
    pDC->SelectObject(pOldFont);

    After I select pOldFont back, Do I need to delete the NewFont and How to ? or the destructor of NewFont will take care of this thing ?

    Thanks!



  2. #2
    Join Date
    Apr 1999
    Posts
    18

    Re: How to destroy a CFont Object that I create

    The destructor will take care of this for you, you only need to call the delete function if previously you allocated memory space with 'new' as follows:

    CFont *m_pPrintFont;
    m_pPrintFont = new CFont;
    ....
    if( m_pPrintFont )
    delete m_pPrintFont;



    Best regards

    Ian

  3. #3
    Join Date
    Apr 1999
    Location
    Miami, FL
    Posts
    67

    Re: How to destroy a CFont Object that I create

    Ian is right. The call which releases the font resource is DeleteObject which the CGdiObject destructor will call for you.

    For questions like these, don't forget that you can always look in the MFC source code to see what's going on, or better yet, Step Into it as you're debugging.

    Regards,

    Alvaro

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured