https://autohotkey.com/board/topic/3816-graphic-buttons/
However, as far as i could test it, it only works on icon and bmp files.
Is it possible to rewrite it so it would also accept PNG files (or an other image with transparency functionality).
Another option would be to rewrite another similar function GuiButtonIcon, maybe this is easier?
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=1985
Code: Select all
AddGraphicButton("SampleButton1", A_WorkingDir . "\icons\Assembly.bmp", "h30 w140 gMyButton", 20, 20)
Gui, Show,, Bitmap Buttons
Return
AddGraphicButton(VariableName, ImgPath, Options="", bHeight=32, bWidth=32)
{
Global
Local ImgType, ImgType1, ImgPath0, ImgPath1, ImgPath2, hwndmode
; BS_BITMAP := 128, IMAGE_BITMAP := 0, BS_ICON := 64, IMAGE_ICON := 1
Static LR_LOADFROMFILE := 16
Static BM_SETIMAGE := 247
Static NULL
SplitPath, ImgPath,,, ImgType1
If ImgPath is float
{
ImgType1 := (SubStr(ImgPath, 1, 1) = "0") ? "bmp" : "ico"
StringSplit, ImgPath, ImgPath,`.
%VariableName%_img := ImgPath2
hwndmode := true
}
ImgTYpe := (ImgType1 = "bmp") ? 128 : 64
If (%VariableName%_img != "") AND !(hwndmode)
DllCall("DeleteObject", "UInt", %VariableName%_img)
If (%VariableName%_hwnd = "")
Gui, Add, Button, v%VariableName% hwnd%VariableName%_hwnd +%ImgType% %Options%
ImgType := (ImgType1 = "bmp") ? 0 : 1
If !(hwndmode)
%VariableName%_img := DllCall("LoadImage", "UInt", NULL, "Str", ImgPath, "UInt", ImgType, "Int", bWidth, "Int", bHeight, "UInt", LR_LOADFROMFILE, "UInt")
DllCall("SendMessage", "UInt", %VariableName%_hwnd, "UInt", BM_SETIMAGE, "UInt", ImgType, "UInt", %VariableName%_img)
Return, %VariableName%_img ; Return the handle to the image
}
Code: Select all
Gui, Add, Button, w22 h22 hwndIcon
if !GuiButtonIcon(Icon, "some.exe") ; Example of Icon not found
GuiButtonIcon(Icon, "shell32.dll") ; Not Found then do this
Gui, Add, Button, w22 h22 hwndIcon
GuiButtonIcon(Icon, A_AhkPath)
Gui, Add, Button, w22 h22 hwndIcon
GuiButtonIcon(Icon, "shell32.dll", 23)
Gui, Add, Button, w38 h38 hwndIcon1
Gui, Add, Button, w38 h38 hwndIcon2
Gui, Add, Button, w70 h38 hwndIcon3, Open
Gui, Add, Button, w70 h38 hwndIcon4, % " Save"
Gui, Add, Button, w70 h60 hwndIcon5, % " Cut`n`n DANGER"
GuiButtonIcon(Icon1, "shell32.dll", 1, "s32")
GuiButtonIcon(Icon2, "imageres.dll", 46, "s32 a1")
GuiButtonIcon(Icon3, "shell32.dll", 46, "s32 a0 l2")
GuiButtonIcon(Icon4, "shell32.dll", 259, "s32 a1 r2")
GuiButtonIcon(Icon5, "shell32.dll", 260, "w40 h22 r20 b20")
Gui, Show
Return
GuiEscape:
GuiClose:
Exitapp
GuiButtonIcon(Handle, File, Index := 1, Options := "")
{
RegExMatch(Options, "i)w\K\d+", W), (W="") ? W := 16 :
RegExMatch(Options, "i)h\K\d+", H), (H="") ? H := 16 :
RegExMatch(Options, "i)s\K\d+", S), S ? W := H := S :
RegExMatch(Options, "i)l\K\d+", L), (L="") ? L := 0 :
RegExMatch(Options, "i)t\K\d+", T), (T="") ? T := 0 :
RegExMatch(Options, "i)r\K\d+", R), (R="") ? R := 0 :
RegExMatch(Options, "i)b\K\d+", B), (B="") ? B := 0 :
RegExMatch(Options, "i)a\K\d+", A), (A="") ? A := 4 :
Psz := A_PtrSize = "" ? 4 : A_PtrSize, DW := "UInt", Ptr := A_PtrSize = "" ? DW : "Ptr"
VarSetCapacity( button_il, 20 + Psz, 0 )
NumPut( normal_il := DllCall( "ImageList_Create", DW, W, DW, H, DW, 0x21, DW, 1, DW, 1 ), button_il, 0, Ptr ) ; Width & Height
NumPut( L, button_il, 0 + Psz, DW ) ; Left Margin
NumPut( T, button_il, 4 + Psz, DW ) ; Top Margin
NumPut( R, button_il, 8 + Psz, DW ) ; Right Margin
NumPut( B, button_il, 12 + Psz, DW ) ; Bottom Margin
NumPut( A, button_il, 16 + Psz, DW ) ; Alignment
SendMessage, BCM_SETIMAGELIST := 5634, 0, &button_il,, AHK_ID %Handle%
return IL_Add( normal_il, File, Index )
}