CreateImageButton() - 2024-01-01

Post your working scripts, libraries and tools.
sashaatx
Posts: 335
Joined: 27 May 2021, 08:27
Contact:

Re: 2.0-beta.1: CreateImageButton() - 2021-08-03 alpha.1

28 Dec 2023, 21:05

jNizM wrote:
10 Jan 2022, 03:18
Interesting. Thank you for your test. So with "simple flat buttons" it is not possible for different colors like hover and pressed?
hope you don't mind a dumb question, I use your darkmode library: viewtopic.php?t=115952

Side by side with CreateImageButton and your bootstrap buttons

Im unable to get the background for buttons to get stylized properly using a basic Ctrl.Opt("Background000000"), curious if you have a remedy?

I attempted to use ControlColor.ahk which includes a gdi32 dllcall but no dice. viewtopic.php?t=119720

I wrote this just for sake of quick testing, combining darkmode and bootstrap buttons in one file.

Code: Select all

#Requires Autohotkey v2
#SingleInstance Force

#Include CreateImageButton.ahk
#Include UseGDIP.ahk 
SetWinDelay(10)
setStyles()
myGui := Gui()
myGui.opt("+Resize +MinSize250x150")
ButtonOK := myGui.Add("Button", "", "&OK")

OkayAgain := myGui.Add("Button", "x+10", "&OK")

Finished := myGui.Add("Button", "", "Finished")
Cancel := myGui.Add("Button", "", "Cancel")

UseGDIP()

StyleButton(ButtonOK, 0, "success")
StyleButton(OkayAgain, 0, "critical-round")

StyleButton(Finished, 0, "info-round")
StyleButton(Cancel, 0, "critical-round")

myGui.OnEvent('Close', (*) => ExitApp())
myGui.Title := "Window"
myGui.Show("w620 h320")


SetWindowAttribute(myGUi)
SetWindowTheme(myGui)


; credit to jNizM
; https://www.autohotkey.com/boards/memberlist.php?mode=viewprofile&u=75

setStyles()
{
    global IBStyles
    IBStyles := Map()
    
    IBStyles["info"] := [[0x80C6E9F4, , , 0, 0x8046B8DA, 1], [0x8086D0E7, , , 0, 0x8046B8DA, 1], [0x8046B8DA, , , 0, 0x8046B8DA, 1], [0xFFF0F0F0, , , 0, 0x8046B8DA, 1]]
    IBStyles["success"] := [[0x80C6E6C6, , , 0, 0x805CB85C, 1], [0x8091CF91, , , 0, 0x805CB85C, 1], [0x805CB85C, , , 0, 0x805CB85C, 1], [0xFFF0F0F0, , , 0, 0x805CB85C, 1]]
    IBStyles["warning"] := [[0x80FCEFDC, , , 0, 0x80F0AD4E, 1], [0x80F6CE95, , , 0, 0x80F0AD4E, 1], [0x80F0AD4E, , , 0, 0x80F0AD4E, 1], [0xFFF0F0F0, , , 0, 0x80F0AD4E, 1]]
    IBStyles["critical"] := [[0x80F0B9B8, , , 0, 0x80D43F3A, 1], [0x80E27C79, , , 0, 0x80D43F3A, 1], [0x80D43F3A, , , 0, 0x80D43F3A, 1], [0xFFF0F0F0, , , 0, 0x80D43F3A, 1]]

    IBStyles["info-outline"] := [[0xFFF0F0F0, , , 0, 0x8046B8DA, 1], [0x80C6E9F4, , , 0, 0x8046B8DA, 1], [0x8086D0E7, , , 0, 0x8046B8DA, 1], [0xFFF0F0F0, , , 0, 0x8046B8DA, 1]]
    IBStyles["success-outline"] := [[0xFFF0F0F0, , , 0, 0x805CB85C, 1], [0x80C6E6C6, , , 0, 0x805CB85C, 1], [0x8091CF91, , , 0, 0x805CB85C, 1], [0xFFF0F0F0, , , 0, 0x805CB85C, 1]]
    IBStyles["warning-outline"] := [[0xFFF0F0F0, , , 0, 0x80F0AD4E, 1], [0x80FCEFDC, , , 0, 0x80F0AD4E, 1], [0x80F6CE95, , , 0, 0x80F0AD4E, 1], [0xFFF0F0F0, , , 0, 0x80F0AD4E, 1]]
    IBStyles["critical-outline"] := [[0xFFF0F0F0, , , 0, 0x80D43F3A, 1], [0x80F0B9B8, , , 0, 0x80D43F3A, 1], [0x80E27C79, , , 0, 0x80D43F3A, 1], [0xFFF0F0F0, , , 0, 0x80D43F3A, 1]]

    IBStyles["info-round"] := [[0x80C6E9F4, , , 8, 0x8046B8DA, 1], [0x8086D0E7, , , 8, 0x8046B8DA, 1], [0x8046B8DA, , , 8, 0x8046B8DA, 1], [0xFFF0F0F0, , , 8, 0x8046B8DA, 1]]
    IBStyles["success-round"] := [[0x80C6E6C6, , , 8, 0x805CB85C, 1], [0x8091CF91, , , 8, 0x805CB85C, 1], [0x805CB85C, , , 8, 0x805CB85C, 1], [0xFFF0F0F0, , , 8, 0x805CB85C, 1]]
    IBStyles["warning-round"] := [[0x80FCEFDC, , , 8, 0x80F0AD4E, 1], [0x80F6CE95, , , 8, 0x80F0AD4E, 1], [0x80F0AD4E, , , 8, 0x80F0AD4E, 1], [0xFFF0F0F0, , , 8, 0x80F0AD4E, 1]]
    IBStyles["critical-round"] := [[0x80F0B9B8, , , 8, 0x80D43F3A, 1], [0x80E27C79, , , 8, 0x80D43F3A, 1], [0x80D43F3A, , , 8, 0x80D43F3A, 1], [0xFFF0F0F0, , , 8, 0x80D43F3A, 1]]

    IBStyles["info-outline-round"] := [[0xFFF0F0F0, , , 8, 0x8046B8DA, 1], [0x80C6E9F4, , , 8, 0x8046B8DA, 1], [0x8086D0E7, , , 8, 0x8046B8DA, 1], [0xFFF0F0F0, , , 8, 0x8046B8DA, 1]]
    IBStyles["success-outline-round"] := [[0xFFF0F0F0, , , 8, 0x805CB85C, 1], [0x80C6E6C6, , , 8, 0x805CB85C, 1], [0x8091CF91, , , 8, 0x805CB85C, 1], [0xFFF0F0F0, , , 8, 0x805CB85C, 1]]
    IBStyles["warning-outline-round"] := [[0xFFF0F0F0, , , 8, 0x80F0AD4E, 1], [0x80FCEFDC, , , 8, 0x80F0AD4E, 1], [0x80F6CE95, , , 8, 0x80F0AD4E, 1], [0xFFF0F0F0, , , 8, 0x80F0AD4E, 1]]
    IBStyles["critical-outline-round"] := [[0xFFF0F0F0, , , 8, 0x80D43F3A, 1], [0x80F0B9B8, , , 8, 0x80D43F3A, 1], [0x80E27C79, , , 8, 0x80D43F3A, 1], [0xFFF0F0F0, , , 8, 0x80D43F3A, 1]]

}


StyleButton(ctrl, offset, style) => CreateImageButton(ctrl, offset, IBStyles[style]*)




SetWindowAttribute(GuiObj, DarkMode := True)
{
    global DarkColors := Map("Background", "0x202020", "Controls", "0x404040", "Font", "0xE0E0E0")
    global TextBackgroundBrush := DllCall("gdi32\CreateSolidBrush", "UInt", DarkColors["Background"], "Ptr")
    static PreferredAppMode := Map("Default", 0, "AllowDark", 1, "ForceDark", 2, "ForceLight", 3, "Max", 4)

    if (VerCompare(A_OSVersion, "10.0.17763") >= 0)
    {
        DWMWA_USE_IMMERSIVE_DARK_MODE := 19
        if (VerCompare(A_OSVersion, "10.0.18985") >= 0)
        {
            DWMWA_USE_IMMERSIVE_DARK_MODE := 20
        }
        uxtheme := DllCall("kernel32\GetModuleHandle", "Str", "uxtheme", "Ptr")
        SetPreferredAppMode := DllCall("kernel32\GetProcAddress", "Ptr", uxtheme, "Ptr", 135, "Ptr")
        FlushMenuThemes := DllCall("kernel32\GetProcAddress", "Ptr", uxtheme, "Ptr", 136, "Ptr")
        switch DarkMode
        {
            case True:
            {
                DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", GuiObj.hWnd, "Int", DWMWA_USE_IMMERSIVE_DARK_MODE, "Int*", True, "Int", 4)
                DllCall(SetPreferredAppMode, "Int", PreferredAppMode["ForceDark"])
                DllCall(FlushMenuThemes)
                GuiObj.BackColor := DarkColors["Background"]
            }
            default:
            {
                DllCall("dwmapi\DwmSetWindowAttribute", "Ptr", GuiObj.hWnd, "Int", DWMWA_USE_IMMERSIVE_DARK_MODE, "Int*", False, "Int", 4)
                DllCall(SetPreferredAppMode, "Int", PreferredAppMode["Default"])
                DllCall(FlushMenuThemes)
                GuiObj.BackColor := "Default"
            }
        }
    }
}


SetWindowTheme(GuiObj, DarkMode := True)
{
    static GWL_WNDPROC := -4
    static GWL_STYLE := -16
    static ES_MULTILINE := 0x0004
    static LVM_GETTEXTCOLOR := 0x1023
    static LVM_SETTEXTCOLOR := 0x1024
    static LVM_GETTEXTBKCOLOR := 0x1025
    static LVM_SETTEXTBKCOLOR := 0x1026
    static LVM_GETBKCOLOR := 0x1000
    static LVM_SETBKCOLOR := 0x1001
    static LVM_GETHEADER := 0x101F
    static GetWindowLong := A_PtrSize = 8 ? "GetWindowLongPtr" : "GetWindowLong"
    static SetWindowLong := A_PtrSize = 8 ? "SetWindowLongPtr" : "SetWindowLong"
    static Init := False
    static LV_Init := False
    global IsDarkMode := DarkMode

    Mode_Explorer := (DarkMode ? "DarkMode_Explorer" : "Explorer")
    Mode_CFD := (DarkMode ? "DarkMode_CFD" : "CFD")
    Mode_ItemsView := (DarkMode ? "DarkMode_ItemsView" : "ItemsView")
    for hWnd, GuiCtrlObj in GuiObj
    {
        switch GuiCtrlObj.Type
        {
            case "Button", "CheckBox", "ListBox", "UpDown":
                {
                    DllCall("uxtheme\SetWindowTheme", "Ptr", GuiCtrlObj.hWnd, "Str", Mode_Explorer, "Ptr", 0)
                }
            case "ComboBox", "DDL":
                {
                    DllCall("uxtheme\SetWindowTheme", "Ptr", GuiCtrlObj.hWnd, "Str", Mode_CFD, "Ptr", 0)
                }
            case "Edit":
                {
                    if (DllCall("user32\" GetWindowLong, "Ptr", GuiCtrlObj.hWnd, "Int", GWL_STYLE) & ES_MULTILINE)
                    {
                        DllCall("uxtheme\SetWindowTheme", "Ptr", GuiCtrlObj.hWnd, "Str", Mode_Explorer, "Ptr", 0)
                    }
                    else
                    {
                        DllCall("uxtheme\SetWindowTheme", "Ptr", GuiCtrlObj.hWnd, "Str", Mode_CFD, "Ptr", 0)
                    }
                }
            case "ListView":
                {
                    if !(LV_Init)
                    {
                        static LV_TEXTCOLOR := SendMessage(LVM_GETTEXTCOLOR, 0, 0, GuiCtrlObj.hWnd)
                        static LV_TEXTBKCOLOR := SendMessage(LVM_GETTEXTBKCOLOR, 0, 0, GuiCtrlObj.hWnd)
                        static LV_BKCOLOR := SendMessage(LVM_GETBKCOLOR, 0, 0, GuiCtrlObj.hWnd)
                        LV_Init := True
                    }
                    GuiCtrlObj.Opt("-Redraw")
                    switch DarkMode
                    {
                        case True:
                        {
                            SendMessage(LVM_SETTEXTCOLOR, 0, DarkColors["Font"], GuiCtrlObj.hWnd)
                            SendMessage(LVM_SETTEXTBKCOLOR, 0, DarkColors["Background"], GuiCtrlObj.hWnd)
                            SendMessage(LVM_SETBKCOLOR, 0, DarkColors["Background"], GuiCtrlObj.hWnd)
                        }
                        default:
                        {
                            SendMessage(LVM_SETTEXTCOLOR, 0, LV_TEXTCOLOR, GuiCtrlObj.hWnd)
                            SendMessage(LVM_SETTEXTBKCOLOR, 0, LV_TEXTBKCOLOR, GuiCtrlObj.hWnd)
                            SendMessage(LVM_SETBKCOLOR, 0, LV_BKCOLOR, GuiCtrlObj.hWnd)
                        }
                    }
                    DllCall("uxtheme\SetWindowTheme", "Ptr", GuiCtrlObj.hWnd, "Str", Mode_Explorer, "Ptr", 0)

                    ; To color the selection - scrollbar turns back to normal
                    ;DllCall("uxtheme\SetWindowTheme", "Ptr", GuiCtrlObj.hWnd, "Str", Mode_ItemsView, "Ptr", 0)

                    ; Header Text needs some NM_CUSTOMDRAW coloring
                    LV_Header := SendMessage(LVM_GETHEADER, 0, 0, GuiCtrlObj.hWnd)
                    DllCall("uxtheme\SetWindowTheme", "Ptr", LV_Header, "Str", Mode_ItemsView, "Ptr", 0)
                    GuiCtrlObj.Opt("+Redraw")
                }
        }
    }

    if !(Init)
    {
        ; https://www.autohotkey.com/docs/v2/lib/CallbackCreate.htm#ExSubclassGUI
        global WindowProcNew := CallbackCreate(WindowProc)  ; Avoid fast-mode for subclassing.
        global WindowProcOld := DllCall("user32\" SetWindowLong, "Ptr", GuiObj.Hwnd, "Int", GWL_WNDPROC, "Ptr", WindowProcNew, "Ptr")
        Init := True
    }

}


WindowProc(hwnd, uMsg, wParam, lParam)
{
    critical
    static WM_CTLCOLOREDIT := 0x0133
    static WM_CTLCOLORLISTBOX := 0x0134
    static WM_CTLCOLORBTN := 0x0135
    static WM_CTLCOLORSTATIC := 0x0138
    static DC_BRUSH := 18

    if (IsDarkMode)
    {
        switch uMsg
        {
            case WM_CTLCOLOREDIT, WM_CTLCOLORLISTBOX:
            {
                DllCall("gdi32\SetTextColor", "Ptr", wParam, "UInt", DarkColors["Font"])
                DllCall("gdi32\SetBkColor", "Ptr", wParam, "UInt", DarkColors["Controls"])
                DllCall("gdi32\SetDCBrushColor", "Ptr", wParam, "UInt", DarkColors["Controls"], "UInt")
                return DllCall("gdi32\GetStockObject", "Int", DC_BRUSH, "Ptr")
            }
            case WM_CTLCOLORBTN:
            {
                DllCall("gdi32\SetDCBrushColor", "Ptr", wParam, "UInt", DarkColors["Background"], "UInt")
                return DllCall("gdi32\GetStockObject", "Int", DC_BRUSH, "Ptr")
            }
            case WM_CTLCOLORSTATIC:
            {
                DllCall("gdi32\SetTextColor", "Ptr", wParam, "UInt", DarkColors["Font"])
                DllCall("gdi32\SetBkColor", "Ptr", wParam, "UInt", DarkColors["Background"])
                return TextBackgroundBrush
            }
        }
    }
    return DllCall("user32\CallWindowProc", "Ptr", WindowProcOld, "Ptr", hwnd, "UInt", uMsg, "Ptr", wParam, "Ptr", lParam)
}
image.png
image.png (1.18 KiB) Viewed 632 times
image.png
image.png (2.12 KiB) Viewed 632 times
image.png
image.png (22.44 KiB) Viewed 628 times
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :
just me
Posts: 9467
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: CreateImageButton() - 2023-07-10

29 Dec 2023, 06:24

@sashaatx:

Code: Select all

; ======================================================================================================================
; How to use:
;     1. ...
;     2. ...
;     3. If you want to change the default Gui background color - needed for rounded buttons -
;        call CreateImageButton("SetDefGuiColor", NewColor) or CreateImageButton("SetDefTxtColor", NewColor)
;        where NewColor is a RGB integer value (0xRRGGBB) or a HTML color name ("Red").
;        To reset the colors to the AHK/system default pass "*INIT*" in NewColor.
When I wrote the function I wasn't aware that Gui.Backcolor can be used to get the value. Maybe I'll add a corresponding option to SetDefGuiColor().

And consider to post questions in "Ask for Help", please.
sashaatx
Posts: 335
Joined: 27 May 2021, 08:27
Contact:

Re: CreateImageButton() - 2023-07-10

31 Dec 2023, 08:19

thanks
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :
sashaatx
Posts: 335
Joined: 27 May 2021, 08:27
Contact:

Re: CreateImageButton() - 2024-01-01

23 Jan 2024, 18:23

super vibrant take on bootstrap buttons with brightness on hover, and other neon colors not pictured
image.png
image.png (85.11 KiB) Viewed 349 times

Code: Select all

; ===============================================================================================================================

IBStyles := Map()
IBStyles["info"] := [[0xFF46B8DA, , , , ,], [0xFF8ED1F0], [0xFF25739E], [0xFFD6D6D6]]
IBStyles["success"] := [[0xFF5CB85C, , , , ,], [0xFFA0EBA0], [0xFF3C7A3C], [0xFFD6D6D6]]
IBStyles["warning"] := [[0xFFF0AD4E, , , , ,], [0xFFFFDC8A], [0xFFBF7E30], [0xFFD6D6D6]]
IBStyles["critical"] := [[0xFFD43F3A, , , , ,], [0xFFFF8780], [0xFFAE2B26], [0xFFD6D6D6]]

IBStyles["info-outline"] := [[0xFFF0F0F0, , , , 0xFF46B8DA, 2], [0xFFB4E5FC], [0xFFA6D6E7], [0xFFF0F0F0]]
IBStyles["success-outline"] := [[0xFFF0F0F0, , , , 0xFF5CB85C, 2], [0xFFD9F2D9], [0xFFB8DAB8], [0xFFF0F0F0]]
IBStyles["warning-outline"] := [[0xFFF0F0F0, , , , 0xFFF0AD4E, 2], [0xFFFFF5DB], [0xFFFFE3B3], [0xFFF0F0F0]]
IBStyles["critical-outline"] := [[0xFFF0F0F0, , , , 0xFFD43F3A, 2], [0xFFFFDFDD], [0xFFFFB3B1], [0xFFF0F0F0]]

IBStyles["info-round"] := [[0xFF46B8DA, , , 8, 0xFF46B8DA, 2], [0xFF8ED1F0], [0xFF25739E], [0xFFF0F0F0]]
IBStyles["success-round"] := [[0xFF5CB85C, , , 8, 0xFF5CB85C, 2], [0xFFA0EBA0], [0xFF3C7A3C], [0xFFF0F0F0]]
IBStyles["warning-round"] := [[0xFFF0AD4E, , , 8, 0xFFF0AD4E, 2], [0xFFFFDC8A], [0xFFBF7E30], [0xFFF0F0F0]]
IBStyles["critical-round"] := [[0xFFD43F3A, , , 8, 0xFFD43F3A, 2], [0xFFFF8780], [0xFFAE2B26], [0xFFF0F0F0]]

IBStyles["info-outline-round"] := [[0xFFF0F0F0, , , 8, 0xFF46B8DA, 2], [0xFFB4E5FC], [0xFFA6D6E7], [0xFFF0F0F0]]
IBStyles["success-outline-round"] := [[0xFFF0F0F0, , , 8, 0xFF5CB85C, 2], [0xFFD9F2D9], [0xFFB8DAB8], [0xFFF0F0F0]]
IBStyles["warning-outline-round"] := [[0xFFF0F0F0, , , 8, 0xFFF0AD4E, 2], [0xFFFFF5DB], [0xFFFFE3B3], [0xFFF0F0F0]]
IBStyles["critical-outline-round"] := [[0xFFF0F0F0, , , 8, 0xFFD43F3A, 2], [0xFFFFDFDD], [0xFFFFB3B1], [0xFFF0F0F0]]
; ===============================================================================================================================

UseGDIP()

MyGui := Gui(, "Bootstrap Buttons")
MyGui.MarginX := 20
MyGui.MarginY := 20
MyGui.SetFont("s11", "Segoe UI")
CreateImageButton("SetDefGuiColor", 0xFFF0F0F0)

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

Btn11 := MyGui.AddButton("xm ym w80 h24", "Info")
CreateImageButton(Btn11, 0, IBStyles["info"]*)

Btn12 := MyGui.AddButton("x+20 yp w80 h24", "Success")
CreateImageButton(Btn12, 0, IBStyles["success"]*)

Btn13 := MyGui.AddButton("x+20 yp w80 h24", "Warning")
CreateImageButton(Btn13, 0, IBStyles["warning"]*)

Btn14 := MyGui.AddButton("x+20 yp w80 h24", "Critical")
CreateImageButton(Btn14, 0, IBStyles["critical"]*)

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

Btn21 := MyGui.AddButton("x+20 yp w80 h24", "Info")
CreateImageButton(Btn21, 0, IBStyles["info-outline"]*)

Btn22 := MyGui.AddButton("x+20 yp w80 h24", "Success")
CreateImageButton(Btn22, 0, IBStyles["success-outline"]*)

Btn23 := MyGui.AddButton("x+20 yp w80 h24", "Warning")
CreateImageButton(Btn23, 0, IBStyles["warning-outline"]*)

Btn24 := MyGui.AddButton("x+20 yp w80 h24", "Critical")
CreateImageButton(Btn24, 0, IBStyles["critical-outline"]*)

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

Btn31 := MyGui.AddButton("xm y+20 w80 h24", "Info")
CreateImageButton(Btn31, 0, IBStyles["info-round"]*)

Btn32 := MyGui.AddButton("x+20 yp w80 h24", "Success")
CreateImageButton(Btn32, 0, IBStyles["success-round"]*)

Btn33 := MyGui.AddButton("x+20 yp w80 h24", "Warning")
CreateImageButton(Btn33, 0, IBStyles["warning-round"]*)

Btn34 := MyGui.AddButton("x+20 yp w80 h24", "Critical")
CreateImageButton(Btn34, 0, IBStyles["critical-round"]*)

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

Btn41 := MyGui.AddButton("x+20 yp w80 h24", "Info")
CreateImageButton(Btn41, 0, IBStyles["info-outline-round"]*)

Btn42 := MyGui.AddButton("x+20 yp w80 h24", "Success")
CreateImageButton(Btn42, 0, IBStyles["success-outline-round"]*)

Btn43 := MyGui.AddButton("x+20 yp w80 h24", "Warning")
CreateImageButton(Btn43, 0, IBStyles["warning-outline-round"]*)

Btn44 := MyGui.AddButton("x+20 yp w80 h24", "Critical")
CreateImageButton(Btn44, 0, IBStyles["critical-outline-round"]*)

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

Btn51 := MyGui.AddButton("xm y+20 w200 h40", "Info")
CreateImageButton(Btn51, 0, IBStyles["info"]*)

Btn52 := MyGui.AddButton("x+20 yp w200 h40", "Success")
CreateImageButton(Btn52, 0, IBStyles["success"]*)

Btn53 := MyGui.AddButton("x+20 yp w200 h40", "Warning")
CreateImageButton(Btn53, 0, IBStyles["warning"]*)

Btn54 := MyGui.AddButton("x+20 yp w200 h40", "Critical")
CreateImageButton(Btn54, 0, IBStyles["critical"]*)

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

Btn61 := MyGui.AddButton("xm y+20 w200 h40", "Info")
CreateImageButton(Btn61, 0, IBStyles["info-outline"]*)

Btn62 := MyGui.AddButton("x+20 yp w200 h40", "Success")
CreateImageButton(Btn62, 0, IBStyles["success-outline"]*)

Btn63 := MyGui.AddButton("x+20 yp w200 h40", "Warning")
CreateImageButton(Btn63, 0, IBStyles["warning-outline"]*)

Btn64 := MyGui.AddButton("x+20 yp w200 h40", "Critical")
CreateImageButton(Btn64, 0, IBStyles["critical-outline"]*)

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

Btn71 := MyGui.AddButton("xm y+20 w200 h40", "Info")
CreateImageButton(Btn71, 0, IBStyles["info-round"]*)

Btn72 := MyGui.AddButton("x+20 yp w200 h40", "Success")
CreateImageButton(Btn72, 0, IBStyles["success-round"]*)

Btn73 := MyGui.AddButton("x+20 yp w200 h40", "Warning")
CreateImageButton(Btn73, 0, IBStyles["warning-round"]*)

Btn74 := MyGui.AddButton("x+20 yp w200 h40", "Critical")
CreateImageButton(Btn74, 0, IBStyles["critical-round"]*)

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

Btn81 := MyGui.AddButton("xm y+20 w200 h40", "Info")
CreateImageButton(Btn81, 0, IBStyles["info-outline-round"]*)

Btn82 := MyGui.AddButton("x+20 yp w200 h40", "Success")
CreateImageButton(Btn82, 0, IBStyles["success-outline-round"]*)

Btn83 := MyGui.AddButton("x+20 yp w200 h40", "Warning")
CreateImageButton(Btn83, 0, IBStyles["warning-outline-round"]*)

Btn84 := MyGui.AddButton("x+20 yp w200 h40", "Critical")
CreateImageButton(Btn84, 0, IBStyles["critical-outline-round"]*)

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

MyGui.Show()

; ===============================================================================================================================

#Include CreateImageButton.ahk
#Include UseGDIP.ahk

other colors

Code: Select all

; ===============================================================================================================================

IBStyles := Map()
IBStyles["electric-blue"] := [[0xFF1E90FF, , , , 0xFFFFFFFF, 1], [0xFF1E90FF, , , , 0xFFFFFF00, 2], [0xFF104E8B, , , , 0xFFFFFFFF, 1], [0xFFD3D3D3, , , , 0xFFFFFFFF, 1]]
IBStyles["neon-green"] := [[0xFF32CD32, , , , 0xFFFFFFFF, 1], [0xFF32CD32, , , , 0xFFFF00FF, 2], [0xFF228B22, , , , 0xFFFFFFFF, 1], [0xFFD3D3D3, , , , 0xFFFFFFFF, 1]]
IBStyles["vivid-coral"] := [[0xFFFF6347, , , , 0xFFFFFFFF, 1], [0xFFFF6347, , , , 0xFF00FFFF, 2], [0xFFCD5C5C, , , , 0xFFFFFFFF, 1], [0xFFD3D3D3, , , , 0xFFFFFFFF, 1]]
IBStyles["bright-violet"] := [[0xFF8A2BE2, , , , 0xFFFFFFFF, 1], [0xFF8A2BE2, , , , 0xFFADFF2F, 2], [0xFF4B0082, , , , 0xFFFFFFFF, 1], [0xFFD3D3D3, , , , 0xFFFFFFFF, 1]]
IBStyles["sunny-yellow"] := [[0xFFFFFF00, , , , 0xFFFFFFFF, 1], [0xFFFFFF00, , , , 0xFFFF69B4, 2], [0xFFBDB76B, , , , 0xFFFFFFFF, 1], [0xFFD3D3D3, , , , 0xFFFFFFFF, 1]]

IBStyles["electric-blue-outline"] := [[0xFFFFFFFF, , , , 0xFF1E90FF, 1], [0xFFFFFFFF, , , , 0xFFFFFF00, 2], [0xFF1E90FF, , , , 0xFF1E90FF, 1], [0xFFD3D3D3, , , , 0xFF1E90FF, 1]]
IBStyles["neon-green-outline"] := [[0xFFFFFFFF, , , , 0xFF32CD32, 1], [0xFFFFFFFF, , , , 0xFFFF00FF, 2], [0xFF32CD32, , , , 0xFF32CD32, 1], [0xFFD3D3D3, , , , 0xFF32CD32, 1]]
IBStyles["vivid-coral-outline"] := [[0xFFFFFFFF, , , , 0xFFFF6347, 1], [0xFFFFFFFF, , , , 0xFF00FFFF, 2], [0xFFFF6347, , , , 0xFFFF6347, 1], [0xFFD3D3D3, , , , 0xFFFF6347, 1]]
IBStyles["bright-violet-outline"] := [[0xFFFFFFFF, , , , 0xFF8A2BE2, 1], [0xFFFFFFFF, , , , 0xFFADFF2F, 2], [0xFF8A2BE2, , , , 0xFF8A2BE2, 1], [0xFFD3D3D3, , , , 0xFF8A2BE2, 1]]
IBStyles["sunny-yellow-outline"] := [[0xFFFFFFFF, , , , 0xFFFFFF00, 1], [0xFFFFFFFF, , , , 0xFFFF69B4, 2], [0xFFFFFF00, , , , 0xFFFFFF00, 1], [0xFFD3D3D3, , , , 0xFFFFFF00, 1]]

IBStyles["electric-blue-round"] := [[0xFF1E90FF, , , 8, 0xFFFFFFFF, 1], [0xFF1E90FF, , , 8, 0xFFFFFF00, 2], [0xFF104E8B, , , 8, 0xFFFFFFFF, 1], [0xFFD3D3D3, , , 8, 0xFFFFFFFF, 1]]
IBStyles["neon-green-round"] := [[0xFF32CD32, , , 8, 0xFFFFFFFF, 1], [0xFF32CD32, , , 8, 0xFFFF00FF, 2], [0xFF228B22, , , 8, 0xFFFFFFFF, 1], [0xFFD3D3D3, , , 8, 0xFFFFFFFF, 1]]
IBStyles["vivid-coral-round"] := [[0xFFFF6347, , , 8, 0xFFFFFFFF, 1], [0xFFFF6347, , , 8, 0xFF00FFFF, 2], [0xFFCD5C5C, , , 8, 0xFFFFFFFF, 1], [0xFFD3D3D3, , , 8, 0xFFFFFFFF, 1]]
IBStyles["bright-violet-round"] := [[0xFF8A2BE2, , , 8, 0xFFFFFFFF, 1], [0xFF8A2BE2, , , 8, 0xFFADFF2F, 2], [0xFF4B0082, , , 8, 0xFFFFFFFF, 1], [0xFFD3D3D3, , , 8, 0xFFFFFFFF, 1]]
IBStyles["sunny-yellow-round"] := [[0xFFFFFF00, , , 8, 0xFFFFFFFF, 1], [0xFFFFFF00, , , 8, 0xFFFF69B4, 2], [0xFFBDB76B, , , 8, 0xFFFFFFFF, 1], [0xFFD3D3D3, , , 8, 0xFFFFFFFF, 1]]
; ===============================================================================================================================

UseGDIP()

MyGui := Gui(, "Bootstrap Buttons")
MyGui.MarginX := 20
MyGui.MarginY := 20
MyGui.SetFont("s11", "Segoe UI")
CreateImageButton("SetDefGuiColor", 0xFFF0F0F0)

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

Btn11 := MyGui.AddButton("xm ym w80 h24", "electric-blue")
CreateImageButton(Btn11, 0, IBStyles["electric-blue"]*)

Btn12 := MyGui.AddButton("x+20 yp w80 h24", "neon-green")
CreateImageButton(Btn12, 0, IBStyles["neon-green"]*)

Btn13 := MyGui.AddButton("x+20 yp w80 h24", "vivid-coral")
CreateImageButton(Btn13, 0, IBStyles["vivid-coral"]*)

Btn14 := MyGui.AddButton("x+20 yp w80 h24", "bright-violet")
CreateImageButton(Btn14, 0, IBStyles["bright-violet"]*)

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

Btn21 := MyGui.AddButton("x+20 yp w80 h24", "electric-blue")
CreateImageButton(Btn21, 0, IBStyles["electric-blue-outline"]*)

Btn22 := MyGui.AddButton("x+20 yp w80 h24", "neon-green")
CreateImageButton(Btn22, 0, IBStyles["neon-green-outline"]*)

Btn23 := MyGui.AddButton("x+20 yp w80 h24", "vivid-coral")
CreateImageButton(Btn23, 0, IBStyles["vivid-coral-outline"]*)

Btn24 := MyGui.AddButton("x+20 yp w80 h24", "bright-violet")
CreateImageButton(Btn24, 0, IBStyles["bright-violet-outline"]*)

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

Btn31 := MyGui.AddButton("xm y+20 w80 h24", "electric-blue")
CreateImageButton(Btn31, 0, IBStyles["electric-blue-round"]*)

Btn32 := MyGui.AddButton("x+20 yp w80 h24", "neon-green")
CreateImageButton(Btn32, 0, IBStyles["neon-green-round"]*)

Btn33 := MyGui.AddButton("x+20 yp w80 h24", "vivid-coral")
CreateImageButton(Btn33, 0, IBStyles["vivid-coral-round"]*)

Btn34 := MyGui.AddButton("x+20 yp w80 h24", "bright-violet")
CreateImageButton(Btn34, 0, IBStyles["bright-violet-round"]*)

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

Btn41 := MyGui.AddButton("x+20 yp w80 h24", "electric-blue")
CreateImageButton(Btn41, 0, IBStyles["electric-blue-round"]*)

Btn42 := MyGui.AddButton("x+20 yp w80 h24", "neon-green")
CreateImageButton(Btn42, 0, IBStyles["neon-green-round"]*)

Btn43 := MyGui.AddButton("x+20 yp w80 h24", "vivid-coral")
CreateImageButton(Btn43, 0, IBStyles["vivid-coral-round"]*)

Btn44 := MyGui.AddButton("x+20 yp w80 h24", "bright-violet")
CreateImageButton(Btn44, 0, IBStyles["bright-violet-round"]*)

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

Btn51 := MyGui.AddButton("xm y+20 w200 h40", "electric-blue")
CreateImageButton(Btn51, 0, IBStyles["electric-blue"]*)

Btn52 := MyGui.AddButton("x+20 yp w200 h40", "neon-green")
CreateImageButton(Btn52, 0, IBStyles["neon-green"]*)

Btn53 := MyGui.AddButton("x+20 yp w200 h40", "vivid-coral")
CreateImageButton(Btn53, 0, IBStyles["vivid-coral"]*)

Btn54 := MyGui.AddButton("x+20 yp w200 h40", "bright-violet")
CreateImageButton(Btn54, 0, IBStyles["bright-violet"]*)

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

Btn61 := MyGui.AddButton("xm y+20 w200 h40", "electric-blue")
CreateImageButton(Btn61, 0, IBStyles["electric-blue-outline"]*)

Btn62 := MyGui.AddButton("x+20 yp w200 h40", "neon-green")
CreateImageButton(Btn62, 0, IBStyles["neon-green-outline"]*)

Btn63 := MyGui.AddButton("x+20 yp w200 h40", "vivid-coral")
CreateImageButton(Btn63, 0, IBStyles["vivid-coral-outline"]*)

Btn64 := MyGui.AddButton("x+20 yp w200 h40", "bright-violet")
CreateImageButton(Btn64, 0, IBStyles["bright-violet-outline"]*)

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

Btn71 := MyGui.AddButton("xm y+20 w200 h40", "electric-blue")
CreateImageButton(Btn71, 0, IBStyles["electric-blue-round"]*)

Btn72 := MyGui.AddButton("x+20 yp w200 h40", "neon-green")
CreateImageButton(Btn72, 0, IBStyles["neon-green-round"]*)

Btn73 := MyGui.AddButton("x+20 yp w200 h40", "vivid-coral")
CreateImageButton(Btn73, 0, IBStyles["vivid-coral-round"]*)

Btn74 := MyGui.AddButton("x+20 yp w200 h40", "bright-violet")
CreateImageButton(Btn74, 0, IBStyles["bright-violet-round"]*)

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

Btn81 := MyGui.AddButton("xm y+20 w200 h40", "electric-blue")
CreateImageButton(Btn81, 0, IBStyles["electric-blue-round"]*)

Btn82 := MyGui.AddButton("x+20 yp w200 h40", "neon-green")
CreateImageButton(Btn82, 0, IBStyles["neon-green-round"]*)

Btn83 := MyGui.AddButton("x+20 yp w200 h40", "vivid-coral")
CreateImageButton(Btn83, 0, IBStyles["vivid-coral-round"]*)

Btn84 := MyGui.AddButton("x+20 yp w200 h40", "bright-violet")
CreateImageButton(Btn84, 0, IBStyles["bright-violet-round"]*)

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

MyGui.Show()

; ===============================================================================================================================

#Include CreateImageButton.ahk
#Include UseGDIP.ahk
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :
mcd
Posts: 2
Joined: 08 Sep 2022, 10:42

Re: CreateImageButton() - 2024-01-01

09 Apr 2024, 11:54

Sorry for the dumb question- Is it possible to add a specific style to all buttons in a GUI without naming each individual button?

I tried this but did not have any luck:

Code: Select all

    for hWnd, controlObj in myGUI {
        if ( controlObj.Type == 'Button' )
            CreateImageButton("ahk_id " hWnd, 0, IBStyles["navy-teal-round"])
    }
pgeugene
Posts: 34
Joined: 27 Jun 2019, 04:36

Re: CreateImageButton() - 2024-01-01

24 Apr 2024, 00:37

I new to AHK
How to link the buttons to action ?
I tried below command but not working.
Thank you

Code: Select all

Btn11 := MyGui.AddButton("xm ym w80 h24", "Info").OnEvent("Click", ButtonClick)
WKen
Posts: 183
Joined: 21 Feb 2023, 00:01

Re: CreateImageButton() - 2024-01-01

24 Apr 2024, 02:39

Your question is not related to this thread and should be posted here: Ask for Help (v2)

Code: Select all

Btn11 := MyGui.AddButton("xm ym w80 h24", "Info").OnEvent("Click", ButtonClick)

ButtonClick(*)
{
	MsgBox(MyGui.FocusedCtrl.text)
}

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: Descolada and 31 guests