I am setting a font created with CreateFont to some dialogbox items using WM_SETFONT.
The font applies correctly. However i am failing to free the font object later when it's not needed anymore.

I have tried getting current object of an item with GetCurrentObject prior to applying the font. Selecting old font object to DC and try to DeleteObject. DeleteObject fails because the new font is still selected into DC for some reason.
Getting current font object with WM_GETFONT doesn't work either. :mad:


p.s. The font object deletes normally when the dialogbox have been destroyed. However I want to delete it while the control is still alive.
Posted on 2005-07-05 09:20:53 by arafel
maybe u can try analyzing it with some memory leaking analysis tool
Posted on 2005-07-05 09:36:03 by comrade
This is how I found the resource leakage in a first place :)
DevPartner BC reports font object leak if the font object doesn't deleted before ending the dialogbox.

I have managed to delete the object outside the dialogbox message procedure after the dialog destroys. However it looks to me like a bad practice. I want to delete it within dialogbox procedure...
Posted on 2005-07-05 09:59:53 by arafel
i've had rare crashes trying to delete dialog icon inside dialog procedure (WM_CLOSE), so maybe it is ok to delete font uotside of dlgproc
Posted on 2005-07-05 10:27:56 by comrade
Ok, I guess i'll stick to deleting it outside the procedure.
Posted on 2005-07-05 14:39:31 by arafel
during writing one of my programs i found out that i had to delete teh brush (which i used as the background in my window)  BEFORE i unregistered the window's class.  when i tried to delete it AFTER UnregisterClass,  DeleteObject was returning an error value.

maybe this'll help you somehow...?
Posted on 2005-07-05 19:18:39 by ti_mo_n