I'm creating icons in my app using LoadIconWithScaleDown()
. I also fall back to CreateIconFromResourceEx()
if the preferred function is not available.
The documentation for DestroyIcon()
states:
It is only necessary to call DestroyIcon for icons and cursors created with the following functions: CreateIconFromResourceEx (if called without the LR_SHARED flag), CreateIconIndirect, and CopyIcon. Do not use this function to destroy a shared icon. A shared icon is valid as long as the module from which it was loaded remains in memory. The following functions obtain a shared icon.
- LoadIcon
- LoadImage (if you use the LR_SHARED flag)
- CopyImage (if you use the LR_COPYRETURNORG flag and the hImage parameter is a shared icon)
- CreateIconFromResource
- CreateIconFromResourceEx (if you use the LR_SHARED flag)
Note: I'm not passing LR_SHARED
to CreateIconFromResourceEx()
; perhaps I should.
What I would like to know is, do I need to call DestroyIcon()
for the icons made with LoadIconWithScaleDown()
?
I would say yes, since the HICON you're getting back does not seem to be shared according to the documentation. Windows obviously does not want you to destroy icons whose handles are shared, but that isn't the case here, and if you fallback to another function that takes LR_SHARED but you're not passing the flag, then that means your process owns the icon handle and you should destroy it when you're done using it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With