[Class] ImageButton - 1.5.00.00 - 20201230

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by iilabs » 30 Dec 2020, 11:28

Thanks for the update!

GamesOfFreak
Posts: 26
Joined: 15 Sep 2020, 03:51
Location: Germany
Contact:

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by GamesOfFreak » 25 Apr 2021, 01:08

It seems, I can't get it to work to make render Image inside the Button. Can I use specific Image Paths for ImageButtons?

I need an Tutorial how to implement the Images.

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by just me » 25 Apr 2021, 07:44

GamesOfFreak wrote:I need an Tutorial how to implement the Images.
README.md

GamesOfFreak
Posts: 26
Joined: 15 Sep 2020, 03:51
Location: Germany
Contact:

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by GamesOfFreak » 25 Apr 2021, 09:05

I found myself how I it works!

c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by c7aesa7r » 17 May 2021, 06:46

@just me How I could get the text of the button control?

Code: Select all

Gui, Add, Button, w60 h18 hwndB1 vB1, B1

Opt1 := {0:1, 1: 0x9b451d, 2:0x9b451d, 3:0x9b451d, 4:"White", 5:8, 6:0x211b18}

; opt2: hover
Opt2 := {2: 0xe6b553, 3:0xe6b553, 4: "White"}  

; opt3: click
Opt3 := {4: "White"}   

If !ImageButton.Create(B1, Opt1, Opt2, Opt3)
   MsgBox, 0, ImageButton Error Btn2, % ImageButton.LastError


; -----------------------------------

GuiControlGet, hwnd, Hwnd , B1
GuiControlGet, text,,B1
ControlGetText, text2, , ahk_id %hwnd%

; blank output here ->
fileappend hwnd:%hwnd% text:%text% text2: %text2%`n,*

; -----------------------------------

Gui, Add, Button, w60 h18 hwndB2 vB2, B2

; -----------------------------------
GuiControlGet, hwnd, Hwnd , B2
GuiControlGet, text,,B2
ControlGetText, text2, , ahk_id %hwnd%
fileappend hwnd:%hwnd% text:%text% text2: %text2%`n,*
; -----------------------------------

gui,show
I tried using GuiControlGet and ControlGetText, but the output variable always returns blank.
The same code in Button2 that is not using the ImageButton class, does return the text correctly.

edit:
Also, I would like to thank you, as always amazing scripts!

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by just me » 17 May 2021, 07:15

@c7aesa7r,
because of problems on Win XP (and maybe later versions) the class contains

Code: Select all

      ; Hide buttons's caption
      ControlSetText, , , ahk_id %HWND%
to remove the button's caption. You might try to comment it out.

c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by c7aesa7r » 17 May 2021, 07:26

@just me Thanks, it does work.

I'm also using your script CtlColorStatic
But sometimes the controls lose all the colors and style, and when i click for example a tab, it does restore the colors, have you seen this before?

c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by c7aesa7r » 21 May 2021, 15:37

image.png
image.png (4.19 KiB) Viewed 6113 times

@just me i tried to modify your function a bit to add support to multi color text inside a button, its almost 'perfect', current problem is to measure the real font size and calculate the space between the texts.

I have added after:

Code: Select all

            ; Draw the text
            DllCall("Gdiplus.dll\GdipDrawString", "Ptr", PGRAPHICS, "WStr", BtnCaption, "Int", -1
                  , "Ptr", PFONT, "Ptr", &RECT, "Ptr", HFORMAT, "Ptr", PBRUSH)
This:

Code: Select all


 
if (oCaption := Option.caption)
{
    
    ; get the current button font and size
    GetFont := GetFont(hwnd)

    fname := % getfont.fontname
    fsize := % getfont.size
    fileappend > font:%fname%`nsize:%fsize% hwnd:%hwnd% `n`n,*

    StringWidth := StringWidth(BtnCaption,GetFont.FontName,GetFont.Size)

    _left += StringWidth 

    ;fileappend StringWidth:%StringWidth% _left:%_left% `n`n,*

    for textColor,text in oCaption 
    {
		 
        ; add space between the text
        BtnCaption := " "
        BtnCaption .= text

        ; try to measure the current caption size
        StringWidth := StringWidth(BtnCaption,GetFont.FontName,GetFont.Size)

        NumPut( _left , RECT,  0, "Float")
        _left += StringWidth
        ;Len := Round(StringWidth/StrLen(BtnCaption))
 
        NumPut(BtnH, RECT, 12, "Float")

        DllCall("Gdiplus.dll\GdipCreateSolidFill", "UInt", textColor, "PtrP", PBRUSH)

        ; Draw the text
        DllCall("Gdiplus.dll\GdipDrawString", "Ptr", PGRAPHICS, "WStr", BtnCaption, "Int", -1
            , "Ptr", PFONT, "Ptr", &RECT, "Ptr", HFORMAT, "Ptr", PBRUSH)

    }

}




; -----------------------------------------
; FUNCTIONS

StringWidth(String, Font:="", FontSize:=10)
{
   ;fileappend font -> %Font% `n,*
   Gui,StringWidth: -DPIScale
	Gui StringWidth:Font, s%FontSize%, %Font%
	Gui StringWidth:Add, Text, R1, %String%
	GuiControlGet T, StringWidth:Pos, Static1
	Gui StringWidth:Destroy
	return TW
}

GetFont(hWnd) {

   static WM_GETFONT := 0x31
                              
   hFont := DllCall("SendMessage", "Ptr", hWnd, "UInt", WM_GETFONT, "Ptr", 0, "Ptr", 0, "Ptr")
   if !hFont {
      Gui, %hWnd%: Add, Text, xp yp wp hp Hidden hwndhText
      hFont := DllCall("SendMessage", "Ptr", hText, "UInt", WM_GETFONT, "Ptr", 0, "Ptr", 0, "Ptr")
      DllCall("DestroyWindow", "Ptr", hText)
   }
   sizeLF := DllCall("GetObject", "Ptr", hFont, "Int", 0, "Ptr", 0)
   VarSetCapacity(LOGFONT, sizeLF, 0)
   DllCall("GetObject", "Ptr", hFont, "Int", sizeLF, "Ptr", &LOGFONT)
   
   Size      :=-NumGet(LOGFONT, "Int")*72//A_ScreenDPI
   Weight    := NumGet(LOGFONT, 16, "Int")
   Italic    := NumGet(LOGFONT, 20, "Char")
   Underline := NumGet(LOGFONT, 21, "Char")
   Strike    := NumGet(LOGFONT, 22, "Char")
   Quality   := NumGet(LOGFONT, 26, "Char")
   FontName  := StrGet(&LOGFONT + 28)
   
   res := {}
   for k, v in ["Size", "Weight", "Italic", "Underline", "Strike", "Quality", "FontName"]
      res[v] := %v%
   Return res
}

; -----------------------------------------

If you could play a bit with the code, you can call it like:

Code: Select all


gui,font,s22,consolas

gui,add,button,w400 h20 hwndHwnd left,button test
 
Opt1 := { 1:5, 2:0x070707,  caption:{ 0xFF1cc400:"some", 0xFFff0000:"text" }, 3:0x070707, 4:0xffffff, 7:0x070707 } 

ImageButton.Create(hwnd,Opt1)

gui,show,h200
return

Try increasing / decreasing the font and also changing the font type, the current problem is, sometimes it don't fit the space between the strings correctly.

Spoiler

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by just me » 22 May 2021, 04:54

Hi @c7aesa7r,

your approach would work only for left aligned singe line buttons, if at all. Currently I'm not interested in multi-coulored button text for Class_ImageButton. If you want to carry on, I recommend to use GDI+ functions for the measuring (e.g. Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)).

c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by c7aesa7r » 22 May 2021, 07:35

Code: Select all


ms:= Gdip_MeasureString(pGraphics, BtnCaption, hFont, hFormat, ByRef RectF)
                  
fileappend ms:%ms% `n`n,*
It output : 0.000000|0.000000|0.000000|0.000000|0|0
Also when I call the function it not draw the coloured text anymore, I'm calling the code above just after

Code: Select all

DllCall("Gdiplus.dll\GdipDrawString"
Edit
Got it now, I need to pass PFont and not hFont in that parameter

fabricio234
Posts: 122
Joined: 06 Mar 2020, 21:48

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by fabricio234 » 23 May 2021, 12:27

@just me is possible to also edit dropdownlist like the things your button lib does?

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by just me » 24 May 2021, 04:32

@fabricio234,

that would be another task because the button of a DDL needs to change it's caption with every new selection.

fabricio234
Posts: 122
Joined: 06 Mar 2020, 21:48

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by fabricio234 » 25 May 2021, 07:32

@just me do you have an example? doesn't matter the caption, just would like to see from where to start

fabricio234
Posts: 122
Joined: 06 Mar 2020, 21:48

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by fabricio234 » 25 May 2021, 19:41

Done:
2021-05-25_21-38-31.gif
2021-05-25_21-38-31.gif (24.18 KiB) Viewed 5956 times
I draw a dropdown under the button and when i hit the button it calls the dropdown.

Do you know if/how to change the border-radius of this white rectangle?
image.png
image.png (1.42 KiB) Viewed 5956 times
I know how to change the text and background color would like to set it to a round border like the button. :think: :think:

ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by ananthuthilakan » 26 May 2021, 03:23

can any body give a direction on how to make this possible with image button
i need to change button caption , but how?

Code: Select all

Gui +ToolWindow
Gui, Add, Button, w100 h25 gStartStop vButtonText, Start
Gui, Show, , Test
Return

StartStop:
GuiControlGet, ButtonText
If ( ButtonText = "Start" ) 
   {
     GuiControl,, ButtonText, Stop
     GoSub, Start
   }
Else
   { 
     GuiControl,, ButtonText, Start
     GoSub, Stop
   }
Return

Start:
Return

Stop:
Return

GuiClose:
 ExitApp
 
 GuiContextMenu:
 reload


ananthuthilakan
Posts: 188
Joined: 08 Jul 2019, 05:37
Contact:

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by ananthuthilakan » 26 May 2021, 03:51

Figured that out, but i would loose the option of text color from image button class.
Now i need to figure out a way to change button text color.

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by jNizM » 09 Jul 2021, 07:59

Example of Bootstrap like Buttons


Image

Code: Select all

#NoEnv
SetBatchLines, -1

; Class ImageButton by just me
; https://www.autohotkey.com/boards/viewtopic.php?t=1103
#Include Class_ImageButton.ahk
; for v1.5 add UseGDIP.ahk or Include them into Class_ImageButton.ahk
; #Include UseGDIP.ahk


Gui, Margin, 20, 20
Gui, Font, s11 normal, Segoe UI

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm ym w80 h24 hWndhBtn11, % "Critical"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1]      ; normal
			   , [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 1]      ; hover
			   , [0, 0x80E27C79, , , 0, , 0x80D43F3A, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1] ]
ImageButton.Create(hBtn11, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn12, % "Warning"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1]      ; normal
			   , [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 1]      ; hover
			   , [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1] ]
ImageButton.Create(hBtn12, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn13, % "Success"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1]      ; normal
			   , [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 1]      ; hover
			   , [0, 0x8091CF91, , , 0, , 0x805CB85C, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1] ]
ImageButton.Create(hBtn13, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn14, % "Info"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1]      ; normal
			   , [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 1]      ; hover
			   , [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1] ]
ImageButton.Create(hBtn14, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, x+20 yp w80 h24 hWndhBtn21, % "Critical"
IBBtnStyles := [ [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 1]      ; normal
			   , [0, 0x80E27C79, , , 0, , 0x80D43F3A, 1]      ; hover
			   , [0, 0x80D43F3A, , , 0, , 0x80D43F3A, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1] ]
ImageButton.Create(hBtn21, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn22, % "Warning"
IBBtnStyles := [ [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 1]      ; normal
			   , [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 1]      ; hover
			   , [0, 0x80F0AD4E, , , 0, , 0x80F0AD4E, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1] ]
ImageButton.Create(hBtn22, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn23, % "Success"
IBBtnStyles := [ [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 1]      ; normal
			   , [0, 0x8091CF91, , , 0, , 0x805CB85C, 1]      ; hover
			   , [0, 0x805CB85C, , , 0, , 0x805CB85C, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1] ]
ImageButton.Create(hBtn23, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn24, % "Info"
IBBtnStyles := [ [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 1]      ; normal
			   , [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 1]      ; hover
			   , [0, 0x8046B8DA, , , 0, , 0x8046B8DA, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1] ]
ImageButton.Create(hBtn24, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm y+20 w80 h24 hWndhBtn31, % "Critical"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; normal
			   , [0, 0x80F0B9B8, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; hover
			   , [0, 0x80E27C79, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1] ]
ImageButton.Create(hBtn31, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn32, % "Warning"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; normal
			   , [0, 0x80FCEFDC, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; hover
			   , [0, 0x80F6CE95, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1] ]
ImageButton.Create(hBtn32, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn33, % "Success"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; normal
			   , [0, 0x80C6E6C6, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; hover
			   , [0, 0x8091CF91, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 1] ]
ImageButton.Create(hBtn33, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn34, % "Info"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; normal
			   , [0, 0x80C6E9F4, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; hover
			   , [0, 0x8086D0E7, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1] ]
ImageButton.Create(hBtn34, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, x+20 yp w80 h24 hWndhBtn41, % "Critical"
IBBtnStyles := [ [0, 0x80F0B9B8, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; normal
			   , [0, 0x80E27C79, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; hover
			   , [0, 0x80D43F3A, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1] ]
ImageButton.Create(hBtn41, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn42, % "Warning"
IBBtnStyles := [ [0, 0x80FCEFDC, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; normal
			   , [0, 0x80F6CE95, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; hover
			   , [0, 0x80F0AD4E, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1] ]
ImageButton.Create(hBtn42, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn43, % "Success"
IBBtnStyles := [ [0, 0x80C6E6C6, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; normal
			   , [0, 0x8091CF91, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; hover
			   , [0, 0x805CB85C, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 1] ]
ImageButton.Create(hBtn43, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn44, % "Info"
IBBtnStyles := [ [0, 0x80C6E9F4, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; normal
			   , [0, 0x8086D0E7, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; hover
			   , [0, 0x8046B8DA, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1] ]
ImageButton.Create(hBtn44, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm y+20 w200 h40 hWndhBtn51, % "Critical"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 2]      ; normal
			   , [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 2]      ; hover
			   , [0, 0x80E27C79, , , 0, , 0x80D43F3A, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 2] ]
ImageButton.Create(hBtn51, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn52, % "Warning"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 2]      ; normal
			   , [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 2]      ; hover
			   , [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 2] ]
ImageButton.Create(hBtn52, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn53, % "Success"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 2]      ; normal
			   , [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 2]      ; hover
			   , [0, 0x8091CF91, , , 0, , 0x805CB85C, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 2] ]
ImageButton.Create(hBtn53, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn54, % "Info"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 2]      ; normal
			   , [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 2]      ; hover
			   , [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 2] ]
ImageButton.Create(hBtn54, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm y+20 w200 h40 hWndhBtn61, % "Critical"
IBBtnStyles := [ [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 2]      ; normal
			   , [0, 0x80E27C79, , , 0, , 0x80D43F3A, 2]      ; hover
			   , [0, 0x80D43F3A, , , 0, , 0x80D43F3A, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 2] ]
ImageButton.Create(hBtn61, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn62, % "Warning"
IBBtnStyles := [ [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 2]      ; normal
			   , [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 2]      ; hover
			   , [0, 0x80F0AD4E, , , 0, , 0x80F0AD4E, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 2] ]
ImageButton.Create(hBtn62, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn63, % "Success"
IBBtnStyles := [ [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 2]      ; normal
			   , [0, 0x8091CF91, , , 0, , 0x805CB85C, 2]      ; hover
			   , [0, 0x805CB85C, , , 0, , 0x805CB85C, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 2] ]
ImageButton.Create(hBtn63, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn64, % "Info"
IBBtnStyles := [ [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 2]      ; normal
			   , [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 2]      ; hover
			   , [0, 0x8046B8DA, , , 0, , 0x8046B8DA, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 2] ]
ImageButton.Create(hBtn64, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm y+20 w200 h40 hWndhBtn71, % "Critical"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 2]      ; normal
			   , [0, 0x80F0B9B8, , , 8, 0xFFF0F0F0, 0x80D43F3A, 2]      ; hover
			   , [0, 0x80E27C79, , , 8, 0xFFF0F0F0, 0x80D43F3A, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 2] ]
ImageButton.Create(hBtn71, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn72, % "Warning"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 2]      ; normal
			   , [0, 0x80FCEFDC, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 2]      ; hover
			   , [0, 0x80F6CE95, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 2] ]
ImageButton.Create(hBtn72, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn73, % "Success"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 2]      ; normal
			   , [0, 0x80C6E6C6, , , 8, 0xFFF0F0F0, 0x805CB85C, 2]      ; hover
			   , [0, 0x8091CF91, , , 8, 0xFFF0F0F0, 0x805CB85C, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 2] ]
ImageButton.Create(hBtn73, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn74, % "Info"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 2]      ; normal
			   , [0, 0x80C6E9F4, , , 8, 0xFFF0F0F0, 0x8046B8DA, 2]      ; hover
			   , [0, 0x8086D0E7, , , 8, 0xFFF0F0F0, 0x8046B8DA, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 2] ]
ImageButton.Create(hBtn74, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Show,, Image Buttons
return


GuiClose:
GuiEscape:
ExitApp
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

ozzii
Posts: 481
Joined: 30 Oct 2013, 06:04

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by ozzii » 09 Jul 2021, 08:11

I like it jNizM

User avatar
iilabs
Posts: 296
Joined: 07 Jun 2020, 16:57

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by iilabs » 09 Jul 2021, 10:19

That’s awesome jNizM. Thanks for sharing.

fenchai
Posts: 292
Joined: 28 Mar 2016, 07:57

Re: [Class] ImageButton - 1.5.00.00 - 20201230

Post by fenchai » 14 Jul 2021, 11:24

jNizM wrote:
09 Jul 2021, 07:59
Example of Bootstrap like Buttons


Image

Code: Select all

#NoEnv
SetBatchLines, -1

; Class ImageButton by just me
; https://www.autohotkey.com/boards/viewtopic.php?t=1103
#Include Class_ImageButton.ahk


Gui, Margin, 20, 20
Gui, Font, s11 normal, Segoe UI

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm ym w80 h24 hWndhBtn11, % "Critical"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1]      ; normal
			   , [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 1]      ; hover
			   , [0, 0x80E27C79, , , 0, , 0x80D43F3A, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1] ]
ImageButton.Create(hBtn11, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn12, % "Warning"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1]      ; normal
			   , [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 1]      ; hover
			   , [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1] ]
ImageButton.Create(hBtn12, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn13, % "Success"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1]      ; normal
			   , [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 1]      ; hover
			   , [0, 0x8091CF91, , , 0, , 0x805CB85C, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1] ]
ImageButton.Create(hBtn13, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn14, % "Info"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1]      ; normal
			   , [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 1]      ; hover
			   , [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1] ]
ImageButton.Create(hBtn14, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, x+20 yp w80 h24 hWndhBtn21, % "Critical"
IBBtnStyles := [ [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 1]      ; normal
			   , [0, 0x80E27C79, , , 0, , 0x80D43F3A, 1]      ; hover
			   , [0, 0x80D43F3A, , , 0, , 0x80D43F3A, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 1] ]
ImageButton.Create(hBtn21, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn22, % "Warning"
IBBtnStyles := [ [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 1]      ; normal
			   , [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 1]      ; hover
			   , [0, 0x80F0AD4E, , , 0, , 0x80F0AD4E, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 1] ]
ImageButton.Create(hBtn22, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn23, % "Success"
IBBtnStyles := [ [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 1]      ; normal
			   , [0, 0x8091CF91, , , 0, , 0x805CB85C, 1]      ; hover
			   , [0, 0x805CB85C, , , 0, , 0x805CB85C, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 1] ]
ImageButton.Create(hBtn23, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn24, % "Info"
IBBtnStyles := [ [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 1]      ; normal
			   , [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 1]      ; hover
			   , [0, 0x8046B8DA, , , 0, , 0x8046B8DA, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 1] ]
ImageButton.Create(hBtn24, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm y+20 w80 h24 hWndhBtn31, % "Critical"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; normal
			   , [0, 0x80F0B9B8, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; hover
			   , [0, 0x80E27C79, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1] ]
ImageButton.Create(hBtn31, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn32, % "Warning"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; normal
			   , [0, 0x80FCEFDC, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; hover
			   , [0, 0x80F6CE95, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1] ]
ImageButton.Create(hBtn32, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn33, % "Success"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; normal
			   , [0, 0x80C6E6C6, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; hover
			   , [0, 0x8091CF91, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 1] ]
ImageButton.Create(hBtn33, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn34, % "Info"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; normal
			   , [0, 0x80C6E9F4, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; hover
			   , [0, 0x8086D0E7, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1] ]
ImageButton.Create(hBtn34, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, x+20 yp w80 h24 hWndhBtn41, % "Critical"
IBBtnStyles := [ [0, 0x80F0B9B8, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; normal
			   , [0, 0x80E27C79, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; hover
			   , [0, 0x80D43F3A, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 1] ]
ImageButton.Create(hBtn41, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn42, % "Warning"
IBBtnStyles := [ [0, 0x80FCEFDC, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; normal
			   , [0, 0x80F6CE95, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; hover
			   , [0, 0x80F0AD4E, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 1] ]
ImageButton.Create(hBtn42, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn43, % "Success"
IBBtnStyles := [ [0, 0x80C6E6C6, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; normal
			   , [0, 0x8091CF91, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; hover
			   , [0, 0x805CB85C, , , 8, 0xFFF0F0F0, 0x805CB85C, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 1] ]
ImageButton.Create(hBtn43, IBBtnStyles*)


Gui, Add, Button, x+20 yp w80 h24 hWndhBtn44, % "Info"
IBBtnStyles := [ [0, 0x80C6E9F4, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; normal
			   , [0, 0x8086D0E7, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; hover
			   , [0, 0x8046B8DA, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 1] ]
ImageButton.Create(hBtn44, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm y+20 w200 h40 hWndhBtn51, % "Critical"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 2]      ; normal
			   , [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 2]      ; hover
			   , [0, 0x80E27C79, , , 0, , 0x80D43F3A, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 2] ]
ImageButton.Create(hBtn51, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn52, % "Warning"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 2]      ; normal
			   , [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 2]      ; hover
			   , [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 2] ]
ImageButton.Create(hBtn52, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn53, % "Success"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 2]      ; normal
			   , [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 2]      ; hover
			   , [0, 0x8091CF91, , , 0, , 0x805CB85C, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 2] ]
ImageButton.Create(hBtn53, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn54, % "Info"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 2]      ; normal
			   , [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 2]      ; hover
			   , [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 2] ]
ImageButton.Create(hBtn54, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm y+20 w200 h40 hWndhBtn61, % "Critical"
IBBtnStyles := [ [0, 0x80F0B9B8, , , 0, , 0x80D43F3A, 2]      ; normal
			   , [0, 0x80E27C79, , , 0, , 0x80D43F3A, 2]      ; hover
			   , [0, 0x80D43F3A, , , 0, , 0x80D43F3A, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80D43F3A, 2] ]
ImageButton.Create(hBtn61, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn62, % "Warning"
IBBtnStyles := [ [0, 0x80FCEFDC, , , 0, , 0x80F0AD4E, 2]      ; normal
			   , [0, 0x80F6CE95, , , 0, , 0x80F0AD4E, 2]      ; hover
			   , [0, 0x80F0AD4E, , , 0, , 0x80F0AD4E, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x80F0AD4E, 2] ]
ImageButton.Create(hBtn62, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn63, % "Success"
IBBtnStyles := [ [0, 0x80C6E6C6, , , 0, , 0x805CB85C, 2]      ; normal
			   , [0, 0x8091CF91, , , 0, , 0x805CB85C, 2]      ; hover
			   , [0, 0x805CB85C, , , 0, , 0x805CB85C, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x805CB85C, 2] ]
ImageButton.Create(hBtn63, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn64, % "Info"
IBBtnStyles := [ [0, 0x80C6E9F4, , , 0, , 0x8046B8DA, 2]      ; normal
			   , [0, 0x8086D0E7, , , 0, , 0x8046B8DA, 2]      ; hover
			   , [0, 0x8046B8DA, , , 0, , 0x8046B8DA, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 0, , 0x8046B8DA, 2] ]
ImageButton.Create(hBtn64, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Add, Button, xm y+20 w200 h40 hWndhBtn71, % "Critical"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 2]      ; normal
			   , [0, 0x80F0B9B8, , , 8, 0xFFF0F0F0, 0x80D43F3A, 2]      ; hover
			   , [0, 0x80E27C79, , , 8, 0xFFF0F0F0, 0x80D43F3A, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80D43F3A, 2] ]
ImageButton.Create(hBtn71, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn72, % "Warning"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 2]      ; normal
			   , [0, 0x80FCEFDC, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 2]      ; hover
			   , [0, 0x80F6CE95, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x80F0AD4E, 2] ]
ImageButton.Create(hBtn72, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn73, % "Success"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 2]      ; normal
			   , [0, 0x80C6E6C6, , , 8, 0xFFF0F0F0, 0x805CB85C, 2]      ; hover
			   , [0, 0x8091CF91, , , 8, 0xFFF0F0F0, 0x805CB85C, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x805CB85C, 2] ]
ImageButton.Create(hBtn73, IBBtnStyles*)


Gui, Add, Button, x+20 yp w200 h40 hWndhBtn74, % "Info"
IBBtnStyles := [ [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 2]      ; normal
			   , [0, 0x80C6E9F4, , , 8, 0xFFF0F0F0, 0x8046B8DA, 2]      ; hover
			   , [0, 0x8086D0E7, , , 8, 0xFFF0F0F0, 0x8046B8DA, 2]      ; pressed
			   , [0, 0x80F0F0F0, , , 8, 0xFFF0F0F0, 0x8046B8DA, 2] ]
ImageButton.Create(hBtn74, IBBtnStyles*)

; ---------------------------------------------------------------------------------------

Gui, Show,, Image Buttons
return


GuiClose:
GuiEscape:
ExitApp
What a mad lad, thank you for your example, hoping to see this with AHK 2 (unlikely but one can only hope lol)

Post Reply

Return to “Scripts and Functions (v1)”