Just starting out? Need help? Post your questions and find answers here.
jacdelad
Addict
Posts: 1477 Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:
Post
by jacdelad » Mon Oct 18, 2021 1:21 pm
Hi, I want to get the dimensions of an icon. I need this for a DLL, the icon is given to the DLL as a handle. Usually I would use GetObject_(), but that does not work with icons (does it?). How do I do this?
Code: Select all
;bitm=LoadImage(1,"D:\PureBasic\Ribbon\Icon1.ico");Icon, please change to a valid icon
bitm=CreateImage(1,32,32);Bitmap
Debug "Handle: "+Str(bitm)
Define temp.bitmap
Debug "Should be 32: "+Str(GetObject_(bitm,SizeOf(temp),@temp))
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
firace
Addict
Posts: 903 Joined: Wed Nov 09, 2011 8:58 am
Post
by firace » Mon Oct 18, 2021 1:49 pm
I have this little procedure but it gets the size from an icon file not handle (from my code library - not thoroughly tested)
Code: Select all
Procedure IconSize(filename$)
If ReadFile(0,filename$) : ReadData(0, *ByteArray, 2048) : EndIf
ProcedureReturn PeekA(*ByteArray + $06)
EndProcedure
i = IconSize(iconfilepath$)
Debug "Size: " + i + "x" + i
jacdelad
Addict
Posts: 1477 Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:
Post
by jacdelad » Mon Oct 18, 2021 3:02 pm
Hello firace,
thanks a lot, but this doesn't help. The DLL just gets the handle and the calling program decides where to get the icon from, so I unfortunately can't use that.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
RASHAD
PureBasic Expert
Posts: 4663 Joined: Sun Apr 12, 2009 6:27 am
Post
by RASHAD » Mon Oct 18, 2021 3:28 pm
If you got the Handle of the Icon
Code: Select all
GetIconInfo_(hIcon, iconinfo.ICONINFO)
GetObject_(iconinfo\hbmMask, SizeOf(BITMAP), bitmap.BITMAP)
width = bitmap\bmWidth
height = bitmap\bmHeight
Egypt my love
jacdelad
Addict
Posts: 1477 Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:
Post
by jacdelad » Mon Oct 18, 2021 3:50 pm
Ah thanks, great. I didn't know the API GetIconInfo_().
BTW, is there a safe way to determine whether my handle is an icon or image, other than trying GetObject_ and when failing doing RASHAD's method?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
RASHAD
PureBasic Expert
Posts: 4663 Joined: Sun Apr 12, 2009 6:27 am
Post
by RASHAD » Mon Oct 18, 2021 4:40 pm
Code: Select all
bitH = LoadImage_(0,GetTemporaryDirectory()+"test.xxx",#IMAGE_BITMAP,16,16,#LR_LOADFROMFILE )
If bitH
Debug "Bitmap"
Else
iconH = LoadImage_(0,GetTemporaryDirectory()+"test.xxx",#IMAGE_ICON ,16,16,#LR_LOADFROMFILE )
If iconH
Debug "Icon"
EndIf
EndIf
Egypt my love
jacdelad
Addict
Posts: 1477 Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:
Post
by jacdelad » Mon Oct 18, 2021 5:17 pm
Can't do that, the image is already loaded and the handle is given to my dll.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
RASHAD
PureBasic Expert
Posts: 4663 Joined: Sun Apr 12, 2009 6:27 am
Post
by RASHAD » Mon Oct 18, 2021 5:24 pm
Then use CopyImage_() with the Handle instead of LoadImage_()
Egypt my love
jacdelad
Addict
Posts: 1477 Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:
Post
by jacdelad » Mon Oct 18, 2021 6:12 pm
...then it's still easier to
Code: Select all
Define dimensions.bitmap,icon.iconinfo
If Not GetObject_(image,SizeOf(dimensions),@dimensions)
GetIconInfo_(image,icon)
GetObject_(icon\hbmMask,SizeOf(dimensions),@dimensions)
EndIf
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB