[Solved] Freeing images/icons created from a procedure?

Windows specific forum
BarryG
Addict
Addict
Posts: 3268
Joined: Thu Apr 18, 2019 8:17 am

[Solved] Freeing images/icons created from a procedure?

Post by BarryG »

I've got code similar to below where images and icons are created from a procedure and given to the main code. However, there doesn't seem to be a way to free the icons when I'm done with them? So, how would you resolve the below and free the icons when done?

Note: My real app doesn't quit, but just needs to free the icons when I want. Also, I can't hard-code the icons because there can any random amount of them created at any given time, from 1 to 999; and also the user will be specifying any file to get them, like the "exe" case below.

Thanks!

Code: Select all

CreateImage(1,32,32,24,#Red) ; A global image to use many times.

Procedure GetIcon(which$)
  Select which$
    Case "red" : i=ImageID(1)
    Case "exe" : i=ExtractIcon_(0,"c:\windows\regedit.exe",0)
  EndSelect
  ProcedureReturn i
EndProcedure

icon1=GetIcon("red")
Debug icon1 ; 65579
Debug IsImage(icon1) ; 0

icon2=GetIcon("exe")
Debug icon2 ; 78775965
Debug IsImage(icon2) ; 0

OpenWindow(0,400,300,60,60,"Icons")
ImageGadget(1,10,10,16,16,icon1)
ImageGadget(2,50,10,16,16,icon2)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow

FreeImage(icon1) ; The specified #Image is not initialised.
FreeImage(icon2) ; The specified #Image is not initialised.
Last edited by BarryG on Mon Oct 18, 2021 12:56 pm, edited 1 time in total.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Freeing images/icons created from a procedure?

Post by Mijikai »

Win API:

Code: Select all

DestroyIcon_()
BarryG
Addict
Addict
Posts: 3268
Joined: Thu Apr 18, 2019 8:17 am

Re: Freeing images/icons created from a procedure?

Post by BarryG »

Thank you!
Post Reply