Archived

This topic is now archived and is closed to further replies.

Askadar

quick MFC cleanup question

Recommended Posts

Hi everybody, I''m using LoadImage to load an image and then attach to a CBitmap. So far no problem. But who''s now responsible for cleaning up the HBITMAP? Will the MFC framework do it, or is it still my job?

Share this post


Link to post
Share on other sites
As soon as you Attach() the handle to the CBitmap, the CBitmap becomes responsable, the handle will be released in it''s destructor.

If you want to prevent the handle from being released when the CBitmap goes of scope, you have to Detach() it again. Then you''re responsable again.


btw: The entire MFC source comes with Visual Studio, you can do ''Edit/Find in files'', set the ''in folder'' box to something like ''c:\Program Files\MICROSOFT VISUAL STUDIO\VC98\MFC\SRC'' and enter a search term, for example ''~CBitmap'' and ''CGdiObject::DeleteObject''

Share this post


Link to post
Share on other sites