1

Тема: AHK: Как добавить Picture на Button в GUI

Как добавить иконку на кнопку в GUI, чтобы при нажатии на кнопку - иконка оставалась на месте.

Gui Add, Button, x17 y5 w64 h64
Gui Add, Picture, x17 y5 w64 h64, icon.png

При наведении на кнопку - кнопка пропадает.
Цель - добавить иконку на кнопку, чтобы иконка не меняла верхний слой.

2

Re: AHK: Как добавить Picture на Button в GUI

Пример:

Gui, Add, Button, w64 h64 hwndhButton1
Gui, Add, Button, x+5 yp+13 w200 h38 hwndhButton2, % "  Этот текст будет виден"

; картинка из png файла
SetImageOnButton(hButton1, "icon.png", 60, 60)
; иконка из dll
SetImageOnButton(hButton2, "Shell32", 24, 24, IMAGE_ICON := 1, 44)

Gui, Show
Return

GuiClose:
   ExitApp

SetImageOnButton(hwnd, imageFilePath, w := 16, h := 16, imageType := 0, iconNumber := 0) {
   static BS_ICON      := 0x40
        , BS_BITMAP    := 0x80
        , IMAGE_ICON   := 1
        , IMAGE_BITMAP := 0
        , BM_SETIMAGE  := 0xF7
        
   if !hImage := LoadPicture(imageFilePath, "w" . w . " h" . h . (iconNumber ? " Icon" . iconNumber : ""), imageType)
      throw "Failed to load image"
   ControlGetText, text,, ahk_id %hwnd%
   if (text = "") {
      WinSet, Style, % "+" . (imageType = IMAGE_ICON ? BS_ICON : BS_BITMAP), ahk_id %hwnd%
      if ErrorLevel
         throw "Failed to assign style"
   }
   SendMessage, BM_SETIMAGE, imageType, hImage,, ahk_id %hwnd%
   if ErrorLevel
      imageType = IMAGE_ICON ? DllCall("DestroyIcon" , "Ptr", ErrorLevel)
                             : DllCall("DeleteObject", "Ptr", ErrorLevel)
}
Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder