|
-
April 15th, 1999, 09:58 AM
#1
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!
-
April 16th, 1999, 10:19 AM
#2
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
-
April 16th, 1999, 04:12 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|