if i create a new brush, "brush1" and a new DC, "dc1" .
i used SelectObject to set dc1 to use brush1.

my question is that when i dont want to use dc1 anymore, i use ReleaseDC to release dc1, at this point: "do i need to use a DeleteObject to delete brush1?"

another situation, when create "brush2", and i use SelectObject to select the new brush2 to dc1, "do i need to use DeleteObject to delete brush1 which i dont want use it anymore?"

Posted on 2002-01-12 09:51:09 by doby
The rules for using GDI objects are simple:

If you make it, umake it when you are done.

If you move something, put it back later.

So if you first CreateObjecct, you will SelectObject, then again SelectObject to restore the object that was there. Finally, you DestroyObject of what you cereated.

Keep this rule sensibly nested, meaning for example if you create a DC to play in, when you are done first restore it's default objects, delete the objects you created, then destroy the DC.
Posted on 2002-01-12 09:55:46 by Ernie
Ya alot of peole want to overlook the data in eax after invoking the SelectObject..

invoke SelectObject, hDC, Object
mov OldObjectOfThisType, eax ; Save it for l8r (save mem leaks)

; destroy DC now (hDC)
invoke SelectObject, hDC, OldObjectOfThisType

if want to keep the object for other DC's dont kill it.
else "invoke DeleteObject, eax" <= 'Object' is returned

invoke DeleteDC, hDC ; Destroy the DC

You get the idea.. Ernie pretty well summed it up for you :)

Posted on 2002-01-12 13:42:37 by NaN
If you have to change a lot of DC's properties you may find usefull SaveDC() and RestoreDC(). Simply call SaveDC(), make changes to DC, use it, call RestoreDC() and finally destroy all objects you created without needing of selecting old ones.
Posted on 2002-01-12 14:08:42 by LuHa