Link to home
Start Free TrialLog in
Avatar of UriS
UriS

asked on

API to delete GDI objects that are not in use

Is there an API that I can call, that will free up the GDI objects that I have created, and finished using ?

We have a heavy application in terms of GDI objects count, and this might be a work around for the main problem.
Avatar of NBrownoh
NBrownoh

Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Avatar of Mike Tomlinson
You have to be careful when creating and deleting GDI objecst as you can suck the life (memory) out of a system really fast by creating too many GDI objects.

As NBrownoh pointed out, you use the DeleteObject() API to delete your objects.

Here is some wisdom I just learned earlier today.  When you use the SelectObject() API, it returns a handle to the previously selected object.  You should then put this object back as the selected object and before deleting the object you just created and used.

Dim hbrush As Long
Dim ret As Long
   
hbrush = GetStockObject(NULLBRUSH) ' create an object
ret = SelectObject(hDC, hbrush) ' store handle to previous object
Polygon hDC, points(0), Me.numVertices ' use the object
SelectObject hDC, ret ' put previous object back
DeleteObject hbrush ' delte the object we created

Regards,

Idle_Mind
Avatar of UriS

ASKER

how can I delete the objects without first saving a pointer to them?
You can't.

Idle_Mind
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial