IcoPath := A_ScriptDir "\google.ico"
if !FileExist(IcoPath)
URLDownloadToFile, https://goo.gl/DFVH4Y, % A_ScriptDir "\google.ico"
DllPath := "Shell32.dll"
IcoIdentifier := 23 ; это не порядковый номер, это идентификатор ресурса
Gui, Add, Button, hwndhButton1 w120 h44
Gui, Add, Button, hwndhButton2 wp hp
SetIconToButton(hButton1, IcoPath, 24)
SetIconToButton(hButton2, DllPath, 32, IcoIdentifier)
Gui, Show
Return
Esc::
GuiClose:
ExitApp
SetIconToButton(hButton, IconFile, IconSize, IcoIdentifier := "") {
static BS_ICON := 0x40, IMAGE_ICON := 1, BM_SETIMAGE := 0xF7, LR_LOADFROMFILE := 0x10
WinSet, Style, % "+" BS_ICON, ahk_id %hButton%
if (IcoIdentifier = "")
hModule := 0, IcoIdentifier := IconFile, flag := LR_LOADFROMFILE
else {
hModule := DllCall("GetModuleHandle", Str, IconFile, Ptr)
if RegExMatch(IcoIdentifier, "^\d+$")
IcoIdentifier := "#" . IcoIdentifier
flag := 0
}
hIcon := DllCall("LoadImage", Ptr, hModule, Str, IcoIdentifier, UInt, IMAGE_ICON, Int, IconSize, Int, IconSize, UInt, flag)
PostMessage, BM_SETIMAGE, IMAGE_ICON, hIcon,, ahk_id %hButton%
}