Date: 02-16-2022
Return to Index
created by gbSnippets
'Once an icon has been inserted into a resource file and compiled into the
'EXE it possible to determine the size of the icon. This information can
'be useful when sizing an imagelist where the resource icon is to be loaded.
'Primary Code:
'PowerBASIC Graphic statements provide limited support of icons, so the
'Windows API have to be used to get the dimensions of a resource icon.
'The GDI API are used to load the image and then use GetObject to extract
'the height/width information.
Local hIcon as DWord, P as IconInfo
hIcon = LoadImage(GetModuleHandle(""), "add", %IMAGE_ICON, 0, 0, %LR_DEFAULTCOLOR)
GetIconInfo hIcon, P
MsgBox Str$(P.xHotSpot) + Str$(P.yHotspot)
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource "gbSnippets.pbr"
Global hDlg as DWord
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Get Size", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local hbmp As DWord, w As Long, h As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
Local Hicon as DWord, P as IconInfo, imgName As AsciiZ * %Max_Path
imgName$ = "add"
hIcon = LoadImage(GetModuleHandle(""), imgName, %IMAGE_ICON, 0, 0, %LR_DEFAULTCOLOR)
GetIconInfo hIcon, P
MsgBox Str$(P.xHotSpot*2) + Str$(P.yHotSpot*2)
DestroyIcon hIcon '
End If
End Function
'gbs_00475
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm