Jump to content

Recommended Posts

Posted (edited)

collection of round buttons

; https://www.autoitscript.com/forum/topic/211721-round-buttons/
;----------------------------------------------------------------------------------------
; Title...........: RoundButtons.au3
; Description.....: collection of round buttons
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $MyGui, $aBtn[7][2]

Example()

Func Example()
    $MyGui = GUICreate(" My GUI Icons", 300, 500)
    $aBtn[0][0] = 6 ; cnt of buttons
    $aBtn[1][1] = "red"
    $aBtn[1][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[1][1] & "_normal.ico", 0, 20, 20, 64, 64, $SS_NOTIFY)
    $aBtn[2][1] = "yellow"
    $aBtn[2][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[2][1] & "_normal.ico", 0, 20, 100, 64, 64, $SS_NOTIFY)
    $aBtn[3][1] = "green"
    $aBtn[3][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[3][1] & "_normal.ico", 0, 20, 180, 64, 64, $SS_NOTIFY)
    $aBtn[4][1] = "turquoise"
    $aBtn[4][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[4][1] & "_normal.ico", 0, 20, 260, 64, 64, $SS_NOTIFY)
    $aBtn[5][1] = "cyan"
    $aBtn[5][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[5][1] & "_normal.ico", 0, 20, 340, 64, 64, $SS_NOTIFY)
    $aBtn[6][1] = "magenta"
    $aBtn[6][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[6][1] & "_normal.ico", 0, 20, 420, 64, 64, $SS_NOTIFY)


    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $aBtn[1][0]
                ConsoleWrite($aBtn[1][1] & @CRLF)
            Case $aBtn[2][0]
                ConsoleWrite($aBtn[2][1] & @CRLF)
            Case $aBtn[3][0]
                ConsoleWrite($aBtn[3][1] & @CRLF)
            Case $aBtn[4][0]
                ConsoleWrite($aBtn[4][1] & @CRLF)
            Case $aBtn[5][0]
                ConsoleWrite($aBtn[5][1] & @CRLF)
            Case $aBtn[6][0]
                ConsoleWrite($aBtn[6][1] & @CRLF)
        EndSwitch

        _IsOver()
    WEnd

    GUIDelete()
EndFunc   ;==>Example

Func _IsOver()
    Local Static $iActive, $iClicked = 0
    Local $aActive = GUIGetCursorInfo($MyGui)

    If $aActive[2] And $iClicked = 1 Then Return

    If $iActive <> $aActive[4] Then
        $iActive = $aActive[4]
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_hover.ico")
            Else
                GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_normal.ico")
            EndIf
        Next
    EndIf

    If $aActive[2] Or $iClicked = 1 Then
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                If $iClicked = 0 Then
                    GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_click.ico")
                    $iClicked = 1
                Else
                    GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_hover.ico")
                    $iClicked = 0
                EndIf
            EndIf
        Next
    EndIf

EndFunc   ;==>_IsOver


Extract buttons folder in @ScriptDir   Buttons.zip

 

Please, every comment is appreciated!
leave your comments and experiences here!
Thank you very much  :)

Edited by ioa747

I know that I know nothing

Posted (edited)
6 hours ago, argumentum said:

And a request would be that the action is on button release ( up ) instead of down

the icon's $SS_NOTIFY style is responsible for this.
I don't know how this can change

Edit:
I found another way

Special Edition:

; https://www.autoitscript.com/forum/topic/211721-round-buttons/
;----------------------------------------------------------------------------------------
; Title...........: RoundButtonsSpecial.au3
; Description.....: collection of round buttons - Special Edition
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Global $MyGui, $aBtn[7][2]

Example()

;----------------------------------------------------------------------------------------
Func Example()
    $MyGui = GUICreate(" My GUI Icons", 300, 500)
    $aBtn[0][0] = 6 ; cnt of buttons
    $aBtn[1][1] = "red"
    $aBtn[1][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[1][1] & "_normal.ico", 0, 20, 20, 64, 64)
    $aBtn[2][1] = "yellow"
    $aBtn[2][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[2][1] & "_normal.ico", 0, 20, 100, 64, 64)
    $aBtn[3][1] = "green"
    $aBtn[3][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[3][1] & "_normal.ico", 0, 20, 180, 64, 64)
    $aBtn[4][1] = "turquoise"
    $aBtn[4][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[4][1] & "_normal.ico", 0, 20, 260, 64, 64)
    $aBtn[5][1] = "cyan"
    $aBtn[5][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[5][1] & "_normal.ico", 0, 20, 340, 64, 64)
    $aBtn[6][1] = "magenta"
    $aBtn[6][0] = GUICtrlCreateIcon(@ScriptDir & "\Buttons\" & $aBtn[6][1] & "_normal.ico", 0, 20, 420, 64, 64)


    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch

        _IsOver()
    WEnd

    GUIDelete()
EndFunc   ;==>Example
;----------------------------------------------------------------------------------------
Func _IsOver()
    Local Static $iActive, $iClicked = 0
    Local $aActive = GUIGetCursorInfo($MyGui)

    If $aActive[2] And $iClicked = 1 Then Return

    If $iActive <> $aActive[4] Then
        $iActive = $aActive[4]
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_hover.ico")
            Else
                GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_normal.ico")
            EndIf
        Next
    EndIf

    If $aActive[2] Or $iClicked = 1 Then
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                If $iClicked = 0 Then
                    GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_click.ico")
                    $iClicked = 1
                Else
                    GUICtrlSetImage($aBtn[$i][0], @ScriptDir & "\Buttons\" & $aBtn[$i][1] & "_hover.ico")
                    $iClicked = 0
                    _ButtonCaller($aBtn[$i][0])
                EndIf
            EndIf
        Next
    EndIf

EndFunc   ;==>_IsOver
;----------------------------------------------------------------------------------------
Func _ButtonCaller($Btn)
    Switch $Btn
        Case $aBtn[1][0]
            ConsoleWrite($aBtn[1][1] & @CRLF)
        Case $aBtn[2][0] ;"yellow"
            ConsoleWrite($aBtn[2][1] & @CRLF)
        Case $aBtn[3][0] ;"green"
            ConsoleWrite($aBtn[3][1] & @CRLF)
        Case $aBtn[4][0] ;"turquoise"
            ConsoleWrite($aBtn[4][1] & @CRLF)
        Case $aBtn[5][0] ;"cyan"
            ConsoleWrite($aBtn[5][1] & @CRLF)
        Case $aBtn[6][0] ;"magenta"
            ConsoleWrite($aBtn[6][1] & @CRLF)
    EndSwitch
EndFunc
;----------------------------------------------------------------------------------------

 

Edited by ioa747
I found another way

I know that I know nothing

  • 3 weeks later...
Posted (edited)

Method for Colorful Rectangle Buttons

; https://www.autoitscript.com/forum/topic/211721-round-buttons/
;----------------------------------------------------------------------------------------
; Title...........: RectButtonsSpecial.au3
; Description.....: collection of rectangles buttons - Special Edition
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

; ~~~~~~~~~~~~~~~~~  Example - what is ColorLight()
Global $test = ColorLight(0xC800C8, 50)
ConsoleWrite($test & @CRLF)

$test = ColorLight(0xC800C8, 50, 1)
ConsoleWrite($test & @CRLF)

$test = ColorLight(0xC800C8, 50, 2)
ConsoleWrite(StringFormat("RGB(%d,%d,%d)", $test[0], $test[1], $test[2]) & @CRLF & @CRLF)
; ~~~~~~~~~~~~  End of Example - what is ColorLight()


Global $MyGui, $aBtn[6][2], $btnColor = 0xC800C8

$MyGui = GUICreate(@ScriptName, 180, 220)
GUISetBkColor(0x000000)

$aBtn[0][0] = 5     ; cnt of buttons

$aBtn[1][0] = GUICtrlCreateLabel("Button1", 10, 20, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[1][1] = 0xA64500
GUICtrlSetBkColor(-1, $aBtn[1][1])

$aBtn[2][0] = GUICtrlCreateLabel("Button2", 10, 60, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[2][1] = 0x826E00
GUICtrlSetBkColor(-1, $aBtn[2][1])

$aBtn[3][0] = GUICtrlCreateLabel("Button3", 10, 100, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[3][1] = 0x268000
GUICtrlSetBkColor(-1, $aBtn[3][1])

$aBtn[4][0] = GUICtrlCreateLabel("Button4", 10, 140, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[4][1] = 0x0094FF
GUICtrlSetBkColor(-1, $aBtn[4][1])

$aBtn[5][0] = GUICtrlCreateLabel("Button5", 10, 180, 150, 30, BitOR($SS_CENTERIMAGE, $SS_CENTER))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$aBtn[5][1] = 0x9600D5
GUICtrlSetBkColor(-1, $aBtn[5][1])

GUISetState(@SW_SHOW)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    _IsOver()
WEnd

;--------------------------------------------------------------------------------------------------------------------------------
Func _IsOver()
    Local Static $iActive, $iClicked = 0
    Local $aActive = GUIGetCursorInfo($MyGui)

    If $aActive[2] And $iClicked = 1 Then Return

    If $iActive <> $aActive[4] And $iClicked = 0 Then
        $iActive = $aActive[4]

        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], 30)) ;hover
            Else
                GUICtrlSetBkColor($aBtn[$i][0], $aBtn[$i][1]) ;normal
            EndIf
        Next
    EndIf

    If $aActive[2] Or $iClicked = 1 Then
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $iActive Then
                If $iClicked = 0 Then
                    GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], -30)) ;click
                    GUICtrlSetFont($aBtn[$i][0], 10, 800, 2, "MS Sans Serif")
                    GUICtrlSetColor($aBtn[$i][0], 0xCCCCCC)
                    $iClicked = 1
                Else
                    GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], 30)) ;hover
                    GUICtrlSetFont($aBtn[$i][0], 10, 800, 0, "MS Sans Serif")
                    GUICtrlSetColor($aBtn[$i][0], 0xFFFFFF)
                    $iClicked = 0
                    _ButtonCaller($aBtn[$i][0])
                EndIf
            EndIf
        Next
    EndIf

EndFunc   ;==>_IsOver
;--------------------------------------------------------------------------------------------------------------------------------
Func _ButtonCaller($Btn)
    Switch $Btn
        Case $aBtn[1][0]
            ConsoleWrite(GUICtrlRead($aBtn[1][0]) & @CRLF)
        Case $aBtn[2][0]
            ConsoleWrite(GUICtrlRead($aBtn[2][0]) & @CRLF)
        Case $aBtn[3][0]
            ConsoleWrite(GUICtrlRead($aBtn[3][0]) & @CRLF)
        Case $aBtn[4][0]
            ConsoleWrite(GUICtrlRead($aBtn[4][0]) & @CRLF)
        Case $aBtn[5][0]
            ConsoleWrite(GUICtrlRead($aBtn[5][0]) & @CRLF)
        Case $aBtn[6][0]
            ConsoleWrite(GUICtrlRead($aBtn[6][0]) & @CRLF)
    EndSwitch
EndFunc   ;==>_ButtonCaller

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: ColorLight()
; Description....: Returns a new color that is a combination of the $HexColor plus the amount of $Lightness it adds to all three RGB channels.
; Syntax.........: ColorLight($HexColor [, $Lightness [,$output]])
; Parameters.....: $HexColor    - The start color to be combined.
;                  $Lightness   - The amount it adds to all three RGB channels. Negative number to subtract (darker)
;                  $output      - Optional: The format of the output string:
;                                     0 = "0x" followed by the hexadecimal value of the new color (default)
;                                     1 = "#" followed by the hexadecimal value of the new color
;                                     2 = an array containing the red, green and blue values of the new color
; Return values..: The new color as a string or an array.
; Author ........: ioa747
; Notes .........:
;--------------------------------------------------------------------------------------------------------------------------------
Func ColorLight($HexColor, $Lightness = 0, $sOutput = 0)

    If StringLeft($HexColor, 1) = "#" Then $HexColor = StringReplace($HexColor, "#", "0x")

    Local $sHexColor = Hex($HexColor, 6)
    ;ConsoleWrite("$sHexColor=" & $sHexColor & @CRLF)

    Local $aSplit = StringSplit($sHexColor, "")
    Local $aRGB[3]

    If $aSplit[0] = 6 Then
        $aRGB[0] = Dec($aSplit[1] & $aSplit[2], 0)
        $aRGB[1] = Dec($aSplit[3] & $aSplit[4], 0)
        $aRGB[2] = Dec($aSplit[5] & $aSplit[6], 0)
        ;ConsoleWrite(StringFormat("aRGB(%d,%d,%d)", $aRGB[0], $aRGB[1], $aRGB[2]) & @CRLF)
    Else
        ConsoleWrite("Something wrong $aSplit[0]=" & $aSplit[0] & @CRLF)
        Return SetError(1, 0, -1)
    EndIf

    Local $aNewRGB[] = [$aRGB[0] + $Lightness, $aRGB[1] + $Lightness, $aRGB[2] + $Lightness]

    If $aNewRGB[0] < 0 Then $aNewRGB[0] = 0
    If $aNewRGB[0] > 255 Then $aNewRGB[0] = 255
    If $aNewRGB[1] < 0 Then $aNewRGB[1] = 0
    If $aNewRGB[1] > 255 Then $aNewRGB[1] = 255
    If $aNewRGB[2] < 0 Then $aNewRGB[2] = 0
    If $aNewRGB[2] > 255 Then $aNewRGB[2] = 255

    ;ConsoleWrite(StringFormat("aNewRGB(%d,%d,%d)", $aNewRGB[0], $aNewRGB[1], $aNewRGB[2]) & @CRLF)

    Local $sColor

    ;$sOutput:  0:="0x" | 1:="#" | 2:=aRGB[R,G,B]
    Switch $sOutput
        Case 0, 1
            $sColor = ($sOutput = 1 ? "#" : "0x")
            $sColor &= Hex(String($aNewRGB[0]), 2)
            $sColor &= Hex(String($aNewRGB[1]), 2)
            $sColor &= Hex(String($aNewRGB[2]), 2)
            ;ConsoleWrite("$sColor=" & $sColor & @CRLF & @CRLF)

        Case 2
            $sColor = $aNewRGB

    EndSwitch

    Return $sColor

EndFunc   ;==>ColorLight
;--------------------------------------------------------------------------------------------------------------------------------

have fun  :)
Thank you very much 

Edited by ioa747
update _IsOver()

I know that I know nothing

  • 8 months later...
  • Solution
Posted (edited)

Method for Colorful  Rectangle Buttons with rounded corners

; https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-1540263
;----------------------------------------------------------------------------------------
; Title...........: RoundRectButtonsSpecial.au3
; Description.....: collection of rectangles buttons - Special Edition
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>

Global $MyGui, $aBtn[6][2]

$MyGui = GUICreate(@ScriptName, 180, 220)
GUISetBkColor(0x000000)
GUISetState(@SW_SHOW)

$aBtn[0][0] = 5     ; cnt of buttons

$aBtn[1][1] = 0xA64500
$aBtn[1][0] = _CreateButton($MyGui, "Button1", 10, 20, 150, 30, $aBtn[1][1], -1, 0xFFFFFF, 10, 800)

$aBtn[2][1] = 0x826E00
$aBtn[2][0] = _CreateButton($MyGui, "Button2", 10, 60, 150, 30, $aBtn[2][1], -1, 0xFFFFFF, 10, 800)

$aBtn[3][1] = 0x268000
$aBtn[3][0] = _CreateButton($MyGui, "Button3", 10, 100, 150, 30, $aBtn[3][1], -1, 0xFFFFFF, 10, 800)

$aBtn[4][1] = 0x0094FF
$aBtn[4][0] = _CreateButton($MyGui, "Button4", 10, 140, 150, 30, $aBtn[4][1], -1, 0xFFFFFF, 10, 800)

$aBtn[5][1] = 0x9600D5
$aBtn[5][0] = _CreateButton($MyGui, "Button5", 10, 180, 150, 30, $aBtn[5][1], -1, 0xFFFFFF, 10, 800)


; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    _IsOver()
WEnd

;---------------------------------------------------------------------------------------
Func _IsOver()
    Local Static $iActive, $iClicked = 0
    Local $aActive = GUIGetCursorInfo($MyGui)

    If $aActive[2] And $iClicked = 1 Then Return

    If $iActive <> $aActive[4] And $iClicked = 0 Then
        $iActive = $aActive[4]

        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $aActive[4] Then
                GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], 30)) ;hover
            Else
                GUICtrlSetBkColor($aBtn[$i][0], $aBtn[$i][1]) ;normal
            EndIf
        Next
    EndIf

    If $aActive[2] Or $iClicked = 1 Then
        For $i = 1 To $aBtn[0][0]
            If $aBtn[$i][0] = $iActive Then
                If $iClicked = 0 Then
                    GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], -30)) ;click
                    GUICtrlSetFont($aBtn[$i][0], 10, 800, 2, "MS Sans Serif")
                    GUICtrlSetColor($aBtn[$i][0], 0xCCCCCC)
                    $iClicked = 1
                Else
                    GUICtrlSetBkColor($aBtn[$i][0], ColorLight($aBtn[$i][1], 30)) ;hover
                    GUICtrlSetFont($aBtn[$i][0], 10, 800, 0, "MS Sans Serif")
                    GUICtrlSetColor($aBtn[$i][0], 0xFFFFFF)
                    $iClicked = 0
                    _ButtonCaller($aBtn[$i][0])
                EndIf
            EndIf
        Next
    EndIf

EndFunc   ;==>_IsOver
;---------------------------------------------------------------------------------------
Func _ButtonCaller($Btn)
    Switch $Btn
        Case $aBtn[1][0]
            ConsoleWrite(GUICtrlRead($aBtn[1][0]) & @CRLF)
        Case $aBtn[2][0]
            ConsoleWrite(GUICtrlRead($aBtn[2][0]) & @CRLF)
        Case $aBtn[3][0]
            ConsoleWrite(GUICtrlRead($aBtn[3][0]) & @CRLF)
        Case $aBtn[4][0]
            ConsoleWrite(GUICtrlRead($aBtn[4][0]) & @CRLF)
        Case $aBtn[5][0]
            ConsoleWrite(GUICtrlRead($aBtn[5][0]) & @CRLF)
        Case $aBtn[6][0]
            ConsoleWrite(GUICtrlRead($aBtn[6][0]) & @CRLF)
    EndSwitch
EndFunc   ;==>_ButtonCaller

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: _CreateButton
; Description....: Creates a button with rounded corners.
; Syntax.........: _CreateButton($hGUI, $Text, $Left, $Top, $Width, $Height, $Color, $Corner = -1, $fColor = -1, $fSize = -1, $fWeight = -1, $fName = -1)
; Parameters.....: $hGUI       - Handle to the parent GUI.
;                  $Text       - Text to display on the button.
;                  $Left       - Horizontal position of the button.
;                  $Top        - Vertical position of the button.
;                  $Width      - Width of the button.
;                  $Height     - Height of the button.
;                  $Color      - Background color of the button.
;                  $Corner     - [optional] Corner radius of the button (default: $Height / 2).
;                  $fColor     - [optional] Font color of the button text (default: 0x000000).
;                  $fSize      - [optional] Font size of the button text (default: $Height * 0.4).
;                  $fWeight    - [optional] Font weight of the button text (default: 400).
;                  $fName      - [optional] Font name of the button text (default: "MS Sans Serif").
; Return values..: The handle to the created button control.
; Author ........: ioa747
; Notes .........: This function uses the WinAPI function CreateRoundRectRgn() and SetWindowRgn() to create a button with rounded corners.
; Link ..........: https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-1540263
; Dependencies...: #include <WinAPIGdi.au3>, #include <WindowsConstants.au3>
;--------------------------------------------------------------------------------------------------------------------------------
Func _CreateButton($hGUI, $Text, $Left, $Top, $Width, $Height, $Color, $Corner = -1, $fColor = -1, $fSize = -1, $fWeight = -1, $fName = -1)

    ; Validate parameters
    If $fColor = Default Or $fColor = -1 Then $fColor = 0x000000
    If $fSize = Default Or $fSize = -1 Then $fSize = $Height * 0.4
    If $fWeight = Default Or $fWeight = -1 Then $fWeight = 400
    If $fName = Default Or $fName = -1 Then $fName = "MS Sans Serif"
    If $Corner < 0 Or $Corner = Default Then $Corner = $Height / 2
    If $Corner > $Height / 2 Then $Corner = $Height
    If $Width <= 0 Or $Height <= 0 Then
        Return SetError(1, 0, 0)
    EndIf

    Local $hChGUI = GUICreate("", $Width, $Height, $Left, $Top, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)
    Local $idLabel = GUICtrlCreateLabel($Text, 0, 0, $Width, $Height, BitOR($SS_CENTER, $SS_NOTIFY, $SS_CENTERIMAGE))
    GUICtrlSetBkColor($idLabel, $Color)
    GUICtrlSetColor($idLabel, $fColor)
    GUICtrlSetFont($idLabel, $fSize, $fWeight, 0, $fName)

    Local $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $Width, $Height, $Corner, $Corner)
    _WinAPI_SetWindowRgn($hChGUI, $hRgn)
    GUISetState()
    Return $idLabel
EndFunc   ;==>_CreateButton


; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: ColorLight()
; Description....: Returns a new color that is a combination of the $HexColor plus the amount of $Lightness it adds to all three RGB channels.
; Syntax.........: ColorLight($HexColor [, $Lightness [,$output]])
; Parameters.....: $HexColor    - The start color to be combined.
;                  $Lightness   - The amount it adds to all three RGB channels. Negative number to subtract (darker)
;                  $output      - Optional: The format of the output string:
;                                     0 = "0x" followed by the hexadecimal value of the new color (default)
;                                     1 = "#" followed by the hexadecimal value of the new color
;                                     2 = an array containing the red, green and blue values of the new color
; Return values..: The new color as a string or an array.
; Author ........: ioa747
; Notes .........:
;--------------------------------------------------------------------------------------------------------------------------------
Func ColorLight($HexColor, $Lightness = 0, $sOutput = 0)

    If StringLeft($HexColor, 1) = "#" Then $HexColor = StringReplace($HexColor, "#", "0x")

    Local $sHexColor = Hex($HexColor, 6)
    ;ConsoleWrite("$sHexColor=" & $sHexColor & @CRLF)

    Local $aSplit = StringSplit($sHexColor, "")
    Local $aRGB[3]

    If $aSplit[0] = 6 Then
        $aRGB[0] = Dec($aSplit[1] & $aSplit[2], 0)
        $aRGB[1] = Dec($aSplit[3] & $aSplit[4], 0)
        $aRGB[2] = Dec($aSplit[5] & $aSplit[6], 0)
        ;ConsoleWrite(StringFormat("aRGB(%d,%d,%d)", $aRGB[0], $aRGB[1], $aRGB[2]) & @CRLF)
    Else
        ConsoleWrite("Something wrong $aSplit[0]=" & $aSplit[0] & @CRLF)
        Return SetError(1, 0, -1)
    EndIf

    Local $aNewRGB[] = [$aRGB[0] + $Lightness, $aRGB[1] + $Lightness, $aRGB[2] + $Lightness]

    If $aNewRGB[0] < 0 Then $aNewRGB[0] = 0
    If $aNewRGB[0] > 255 Then $aNewRGB[0] = 255
    If $aNewRGB[1] < 0 Then $aNewRGB[1] = 0
    If $aNewRGB[1] > 255 Then $aNewRGB[1] = 255
    If $aNewRGB[2] < 0 Then $aNewRGB[2] = 0
    If $aNewRGB[2] > 255 Then $aNewRGB[2] = 255

    ;ConsoleWrite(StringFormat("aNewRGB(%d,%d,%d)", $aNewRGB[0], $aNewRGB[1], $aNewRGB[2]) & @CRLF)

    Local $sColor

    ;$sOutput:  0:="0x" | 1:="#" | 2:=aRGB[R,G,B]
    Switch $sOutput
        Case 0, 1
            $sColor = ($sOutput = 1 ? "#" : "0x")
            $sColor &= Hex(String($aNewRGB[0]), 2)
            $sColor &= Hex(String($aNewRGB[1]), 2)
            $sColor &= Hex(String($aNewRGB[2]), 2)
            ;ConsoleWrite("$sColor=" & $sColor & @CRLF & @CRLF)

        Case 2
            $sColor = $aNewRGB

    EndSwitch

    Return $sColor

EndFunc   ;==>ColorLight

have fun  :)
Thank you very much 

 

Edited by ioa747
update _IsOver()

I know that I know nothing

Posted

GDIPlus approach for Colorful  Rectangle Buttons with rounded corners
from https://www.autoitscript.com/forum/topic/212626-how-to-create-rounded-corners-_gdiplus/

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>

Global $hGraphic, $hBrush, $hBrushFont, $hFont, $hFormat, $hFamily, $hGUI, $tRect_Coords[4]
Global $iTheme = 0

Example()

;---------------------------------------------------------------------------------------
Func Example()

    ; Create GUI
    $hGUI = GUICreate("GDI+ Centered Text", 400, 300)

    ; Initialize GDI+
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ; antialiasing

    $hBrush = _GDIPlus_BrushCreateSolid(0xAA43A6DF) ; Blue
    $hBrushFont = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) ; White
    $hFormat = _GDIPlus_StringFormatCreate()
    _GDIPlus_StringFormatSetAlign($hFormat, 1) ; Horizontal alignment
    _GDIPlus_StringFormatSetLineAlign($hFormat, 1) ; Vertical alignment
    $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI Light")
    $hFont = _GDIPlus_FontCreate($hFamily, 20, 2)

    ; Rectangle coordinates
    $tRect_Coords[0] = 50
    $tRect_Coords[1] = 50
    $tRect_Coords[2] = 200
    $tRect_Coords[3] = 100

    ; Register for painting
    GUIRegisterMsg($WM_PAINT, "WM_PAINT")

    GUISetState()

    ; Loop until the user exits
    Do
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $GUI_EVENT_PRIMARYDOWN
                If CheckPointer($tRect_Coords) Then SetTheme(1)

            Case $GUI_EVENT_PRIMARYUP
                SetTheme(0)

            Case $GUI_EVENT_MOUSEMOVE
                If GetTheme() = 1 Then ContinueLoop
                If CheckPointer($tRect_Coords) Then
                    SetTheme(2)
                Else
                    SetTheme(0)
                EndIf

        EndSwitch
    Until 0

    ; Clean up resources
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BrushDispose($hBrushFont)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>Example
;---------------------------------------------------------------------------------------
Func WM_PAINT($hGUI, $iMsg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)

    ; Clear the canvas
    _GDIPlus_GraphicsClear($hGraphic, 0xFFF0F0F0)

    ; Create a path for the rounded rectangle
    Local $hPath = _GDIPlus_PathCreate()
    _GDIPlus_PathAddRoundRect($hPath, $tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3], 50)
;~  _GDIPlus_PathAddRoundRect($hPath, $tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3], 20)

    ; Fill the rounded rectangle
    _GDIPlus_GraphicsFillPath($hGraphic, $hPath, $hBrush)

    ; Optionally draw the outline
    Local $hPen = _GDIPlus_PenCreate(0xFF3685B2, 2) ; Darker Blue border
    _GDIPlus_GraphicsDrawPath($hGraphic, $hPath, $hPen)

    ; Draw the string centered in the rectangle
    _GDIPlus_GraphicsDrawStringEx($hGraphic, "Click Me", $hFont, _GDIPlus_RectFCreate($tRect_Coords[0], $tRect_Coords[1], $tRect_Coords[2], $tRect_Coords[3]), $hFormat, $hBrushFont)

    ; Clean up
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PathDispose($hPath)

    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return 0
EndFunc   ;==>WM_PAINT
;---------------------------------------------------------------------------------------
Func CheckPointer(ByRef $aiCoords_ClientRel)
    Return _WinAPI_PtInRectEx(_WinAPI_GetMousePosX(True, $hGUI), _WinAPI_GetMousePosY(True, $hGUI), $aiCoords_ClientRel[0], $aiCoords_ClientRel[1], $aiCoords_ClientRel[0] + $aiCoords_ClientRel[2], $aiCoords_ClientRel[1] + $aiCoords_ClientRel[3])
EndFunc   ;==>CheckPointer
;---------------------------------------------------------------------------------------
Func GetTheme()
    Return $iTheme
EndFunc   ;==>GetTheme
;---------------------------------------------------------------------------------------
Func SetTheme($Theme, $f_Redraw = True)
    If GetTheme() = $Theme Then Return 1

    If $Theme = 0 Then ; Idle
        _GDIPlus_BrushSetSolidColor($hBrush, 0xAA43A6DF) ; Blue
        $tRect_Coords[0] = 50
        $tRect_Coords[1] = 50

    ElseIf $Theme = 1 Then ; MouseDown
        _GDIPlus_BrushSetSolidColor($hBrush, 0xFF3685B2) ; Darker Blue
        $tRect_Coords[0] = 52
        $tRect_Coords[1] = 52 ; Move slightly down

    ElseIf $Theme = 2 Then ; MouseOver
        _GDIPlus_BrushSetSolidColor($hBrush, 0xBB7BC1E9) ; Lighter Blue
        $tRect_Coords[0] = 50
        $tRect_Coords[1] = 50

    Else
        Return SetError(1, 0, 0)
    EndIf

    $iTheme = $Theme
    If $f_Redraw Then _WinAPI_RedrawWindow($hGUI, 0, 0, BitOR($RDW_INTERNALPAINT, $RDW_ERASE))

EndFunc   ;==>SetTheme
;---------------------------------------------------------------------------------------
Func _GDIPlus_PathAddRoundRect(ByRef $hPath, $iX, $iY, $iWidth, $iHeight, $iRadius)
    Local $iDiameter = $iRadius * 2
    _GDIPlus_PathAddArc($hPath, $iX, $iY, $iDiameter, $iDiameter, 180, 90)
    _GDIPlus_PathAddLine($hPath, $iX + $iRadius, $iY, $iX + $iWidth - $iRadius, $iY)
    _GDIPlus_PathAddArc($hPath, $iX + $iWidth - $iDiameter, $iY, $iDiameter, $iDiameter, 270, 90)
    _GDIPlus_PathAddLine($hPath, $iX + $iWidth, $iY + $iRadius, $iX + $iWidth, $iY + $iHeight - $iRadius)
    _GDIPlus_PathAddArc($hPath, $iX + $iWidth - $iDiameter, $iY + $iHeight - $iDiameter, $iDiameter, $iDiameter, 0, 90)
    _GDIPlus_PathAddLine($hPath, $iX + $iWidth - $iRadius, $iY + $iHeight, $iX + $iRadius, $iY + $iHeight)
    _GDIPlus_PathAddArc($hPath, $iX, $iY + $iHeight - $iDiameter, $iDiameter, $iDiameter, 90, 90)
    _GDIPlus_PathAddLine($hPath, $iX, $iY + $iHeight - $iRadius, $iX, $iY + $iRadius)
EndFunc   ;==>_GDIPlus_PathAddRoundRect
;---------------------------------------------------------------------------------------


have fun  :)
Thank you very much 

I know that I know nothing

Posted (edited)

Example gif button with transparent background on transparent gui

; https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-1540267
;----------------------------------------------------------------------------------------
; Title...........: _GUICtrlCreateButton57
; Description.....: Example gif button with transparent background on tranparent gui
; AutoIt Version..: 3.3.16.1   Author: ioa747  Script Version: 1.0
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#NoTrayIcon
#include <GUIConstants.au3>
#include <WinAPIShellEx.au3>
#include <WinAPISysWin.au3>
#include <Misc.au3>
#include <GDIPlus.au3>

Global $mBtn[] ; map to hold Buttons arguments

_MyCustomGUI()

;---------------------------------------------------------------------------------------
Func _MyCustomGUI()
    _WinAPI_SetCurrentProcessExplicitAppUserModelID(StringTrimRight(@ScriptName, 4) & ".v1.0")
    TraySetIcon("shell32.dll", -246)
    Opt("TrayAutoPause", 0)

    Local $hGui = GUICreate("My Custom GUI", 640, 400, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
    GUISetIcon("shell32.dll", -246)
    GUISetBkColor(0x000000) ; 0x000000
    WinSetTrans($hGui, "", 150)

    ; Close Button
    Local $idBtnClose = GUICtrlCreateButton("Close", 4, 4, 24, 24, $BS_ICON)
    GUICtrlSetImage($idBtnClose, "shell32.dll", -216)

    ; Parent Drag area
    GUICtrlCreateLabel("", 0, 0, 32, 400, $SS_BLACKFRAME, $GUI_WS_EX_PARENTDRAG)

    ; Page Label
    GUICtrlCreateLabel("Page 1", 220, 20, 180, 30)
    GUICtrlSetFont(-1, 18, 600, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF) ; 0xFFFFFF
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

    ; Buttons
    Local $Btn1 = _GUICtrlCreateButton57("Button1", 100, 300, $hGui)
    Local $Btn2 = _GUICtrlCreateButton57("Button2", 350, 300, $hGui)

    GUISetState(@SW_SHOW, $hGui)

    Local $hDLL = DllOpen("user32.dll") ; _IsPressed needed

    ; Draw Gui Title string
    _GDIPlus_Startup()
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGui)
    _GDIPlus_GraphicsDrawString($hGraphic, "My Custom GUI", 5, 50, Default, 12, 0x0002, 0xFFFFFFFF)


    Local $idMsg
    While 1
        $idMsg = GUIGetMsg()
        Switch $idMsg
            Case $GUI_EVENT_CLOSE, $idBtnClose
                ExitLoop

            Case $mBtn[$Btn1].id, $mBtn[$Btn2].id
                ; mouse down
                GUICtrlSetFont($mBtn[$mBtn.Active].label, 14, 600, 2, "MS Sans Serif")
                GUICtrlSetImage($mBtn[$mBtn.Active].id, ".\gif\buttons_blue75_pressed.gif")
                While _IsPressed("01", $hDLL) ; 01=Left mouse button
                    Sleep(100)
                WEnd
                ; mouse up
                GUICtrlSetFont($mBtn[$mBtn.Active].label, 14, ($mBtn.Active = $mBtn.Active ? 600 : 400), 0, "MS Sans Serif")
                GUICtrlSetImage($mBtn[$mBtn.Active].id, ($mBtn.Active = $mBtn.Active ? _
                        ".\gif\buttons_blue75_hoover.gif" : ".\gif\buttons_blue75.gif"))

                ConsoleWrite("click on: " & $mBtn[$mBtn.Active].text & @CRLF)

        EndSwitch

        _ButtonHoover()

    WEnd
    DllClose($hDLL)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
EndFunc   ;==>_MyCustomGUI
;---------------------------------------------------------------------------------------
Func _GUICtrlCreateButton57($text, $left, $top, $hGuiParent)
    Local $hGui = GUICreate("", 200, 46, $left, $top, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGuiParent)
    Local $idPic = GUICtrlCreatePic(".\gif\buttons_blue75.gif", 0, 0, 0, 0, $SS_NOTIFY)
    Local $idLbl = GUICtrlCreateLabel($text, 17, 12, 167, 23, $SS_CENTER)
    GUICtrlSetFont(-1, 14, 500, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x000000)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUISetState(@SW_SHOW, $hGui)
    Local $map[]
    $map.id = $idPic
    $map.label = $idLbl
    $map.text = $text
    $mBtn[$hGui] = $map
    Return $hGui
EndFunc   ;==>_GUICtrlCreateButton57
;---------------------------------------------------------------------------------------
Func _ButtonHoover()
    Local Static $hActivehWnd
    Local Static $tStruct = DllStructCreate($tagPOINT)

    Local $aMpos = MouseGetPos()
    DllStructSetData($tStruct, "x", $aMpos[0])
    DllStructSetData($tStruct, "y", $aMpos[1])

    Local $hParentWnd = _WinAPI_WindowFromPoint($tStruct)
    Local $hWnd = _WinAPI_GetParent($hParentWnd)

    If $hActivehWnd = $hWnd Then Return

    If MapExists($mBtn, $hWnd) Then
        GUICtrlSetFont($mBtn[$hWnd].label, 14, 600, 0, "MS Sans Serif")
        GUICtrlSetColor($mBtn[$hWnd].label, 0xFFFFFF)
        GUICtrlSetImage($mBtn[$hWnd].id, ".\gif\buttons_blue75_hoover.gif")
    EndIf

    If MapExists($mBtn, $hActivehWnd) Then
        GUICtrlSetFont($mBtn[$hActivehWnd].label, 14, 400, 0, "MS Sans Serif")
        GUICtrlSetColor($mBtn[$hActivehWnd].label, 0x000000)
        GUICtrlSetImage($mBtn[$hActivehWnd].id, ".\gif\buttons_blue75.gif")
    EndIf

    $hActivehWnd = $hWnd
    $mBtn.Active = $hWnd

EndFunc   ;==>_ButtonHoover
;---------------------------------------------------------------------------------------

 

gif.zip

 

have fun  :)
Thank you very much 

 

Edited by ioa747

I know that I know nothing

Posted (edited)

diving into maps, an approach using a map of maps
to better express the click effect

rectangles buttons with rounded corners - Map Edition

; https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-1540263
;----------------------------------------------------------------------------------------
; Title...........: RoundRectButtonsMap.au3
; Description.....: rectangles buttons with rounded corners - Map Edition
; AutoIt Version..: 3.3.16.1   Author: ioa747
; Note............: Testet in Win10 22H2
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
#include <Array.au3>

Global $MyGui

$MyGui = GUICreate(@ScriptName, 180, 220)
GUISetBkColor(0x000000)
GUISetState(@SW_SHOW)

Global $mCtrl[], $m[]

$m.id = _CreateButton($MyGui, "Button1", 10, 20, 150, 30, 0xA64500, -1, 0xFFFFFF, 10, 800)
$mCtrl[$m.id] = $m

$m.id = _CreateButton($MyGui, "Button2", 10, 60, 150, 30, 0x826E00, -1, 0xFFFFFF, 10, 800)
$mCtrl[$m.id] = $m

$m.id = _CreateButton($MyGui, "Button3", 10, 100, 150, 30, 0x268000, -1, 0xFFFFFF, 10, 800)
$mCtrl[$m.id] = $m

$m.id = _CreateButton($MyGui, "Button4", 10, 140, 150, 30, 0x0094FF, -1, 0xFFFFFF, 10, 800)
$mCtrl[$m.id] = $m

$m.id = _CreateButton($MyGui, "Button5", 10, 180, 150, 30, 0x9600D5, -1, 0xFFFFFF, 10, 800)
$mCtrl[$m.id] = $m

Global $aM = MapKeys($mCtrl)

;~ _ArrayDisplay($aM)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    _IsOver()
WEnd

;---------------------------------------------------------------------------------------
Func _IsOver()
    Local Static $iActive, $iClicked = 0
    Local $aActive = GUIGetCursorInfo($MyGui)

    If $aActive[2] And $iClicked = 1 Then Return

    If $iActive <> $aActive[4] And $iClicked = 0 Then
        $iActive = $aActive[4]

        For $i = 0 To UBound($aM) - 1
            If $aM[$i] = $iActive Then
                GUICtrlSetBkColor($aM[$i], ColorLight($mCtrl[$aM[$i]].color, 30)) ;hover
            Else
                GUICtrlSetBkColor($aM[$i], $mCtrl[$aM[$i]].color) ;normal
            EndIf
        Next
    EndIf

    If $aActive[2] Or $iClicked = 1 Then
        For $i = 0 To UBound($aM) - 1
            If $aM[$i] = $iActive Then
                If $iClicked = 0 Then
                    WinMove($mCtrl[$aM[$i]].hwnd, "", $mCtrl[$aM[$i]].left + 2, $mCtrl[$aM[$i]].top + 2)
                    GUICtrlSetBkColor($aM[$i], ColorLight($mCtrl[$aM[$i]].color, -30)) ;click
                    GUICtrlSetFont($aM[$i], $mCtrl[$aM[$i]].fsize, $mCtrl[$aM[$i]].fweight, 2, $mCtrl[$aM[$i]].fname)
                    GUICtrlSetColor($aM[$i], 0xCCCCCC)
                    $iClicked = 1
                Else
                    WinMove($mCtrl[$aM[$i]].hwnd, "", $mCtrl[$aM[$i]].left, $mCtrl[$aM[$i]].top)
                    GUICtrlSetBkColor($aM[$i], ColorLight($mCtrl[$aM[$i]].color, 30)) ;hover
                    GUICtrlSetFont($aM[$i], $mCtrl[$aM[$i]].fsize, $mCtrl[$aM[$i]].fweight, 0, $mCtrl[$aM[$i]].fname)
                    GUICtrlSetColor($aM[$i], 0xFFFFFF)
                    $iClicked = 0
                    _ButtonCaller($aM[$i])
                EndIf
            EndIf
        Next
    EndIf

EndFunc   ;==>_IsOver
;---------------------------------------------------------------------------------------
Func _ButtonCaller($Btn)

    ConsoleWrite("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].id: " & $mCtrl[$Btn].id & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].text: " & $mCtrl[$Btn].text & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].left: " & $mCtrl[$Btn].left & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].top: " & $mCtrl[$Btn].top & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].width: " & $mCtrl[$Btn].width & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].height: " & $mCtrl[$Btn].height & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].color: " & $mCtrl[$Btn].color & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].corner: " & $mCtrl[$Btn].corner & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].fcolor: " & $mCtrl[$Btn].fcolor & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].fsize: " & $mCtrl[$Btn].fsize & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].fweight: " & $mCtrl[$Btn].fweight & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].fname: " & $mCtrl[$Btn].fname & @CRLF)
    ConsoleWrite("$mCtrl[" & $Btn & "].hwnd: " & $mCtrl[$Btn].hwnd & @CRLF)

EndFunc   ;==>_ButtonCaller

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: _CreateButton
; Description....: Creates a button with rounded corners.
; Syntax.........: _CreateButton($hGUI, $Text, $Left, $Top, $Width, $Height, $Color, $Corner = -1, $fColor = -1, $fSize = -1, $fWeight = -1, $fName = -1)
; Parameters.....: $hGUI       - Handle to the parent GUI.
;                  $Text       - Text to display on the button.
;                  $Left       - Horizontal position of the button.
;                  $Top        - Vertical position of the button.
;                  $Width      - Width of the button.
;                  $Height     - Height of the button.
;                  $Color      - Background color of the button.
;                  $Corner     - [optional] Corner radius of the button (default: $Height / 2).
;                  $fColor     - [optional] Font color of the button text (default: 0x000000).
;                  $fSize      - [optional] Font size of the button text (default: $Height * 0.4).
;                  $fWeight    - [optional] Font weight of the button text (default: 400).
;                  $fName      - [optional] Font name of the button text (default: "MS Sans Serif").
; Return values..: The handle to the created button control.
; Author ........: ioa747
; Notes .........: This function uses the WinAPI function CreateRoundRectRgn() and SetWindowRgn() to create a button with rounded corners.
; Link ..........: https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-1540263
; Dependencies...: #include <WinAPIGdi.au3>, #include <WindowsConstants.au3>
;--------------------------------------------------------------------------------------------------------------------------------
Func _CreateButton($hGUI, $Text, $Left, $Top, $Width, $Height, $Color, $Corner = -1, $fColor = -1, $fSize = -1, $fWeight = -1, $fName = -1)

    ; Validate parameters
    If $fColor = Default Or $fColor = -1 Then $fColor = 0x000000
    If $fSize = Default Or $fSize = -1 Then $fSize = $Height * 0.4
    If $fWeight = Default Or $fWeight = -1 Then $fWeight = 400
    If $fName = Default Or $fName = -1 Then $fName = "MS Sans Serif"
    If $Corner < 0 Or $Corner = Default Then $Corner = $Height / 2
    If $Corner > $Height / 2 Then $Corner = $Height
    If $Width <= 0 Or $Height <= 0 Then
        Return SetError(1, 0, 0)
    EndIf

    $m.text = $Text
    $m.left = $Left
    $m.top = $Top
    $m.width = $Width
    $m.height = $Height
    $m.color = $Color
    $m.corner = $Corner
    $m.fcolor = $fColor
    $m.fsize = $fSize
    $m.fweight = $fWeight
    $m.fname = $fName

    Local $hChGUI = GUICreate("", $Width, $Height, $Left, $Top, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)
    $m.hwnd = $hChGUI
    Local $idLabel = GUICtrlCreateLabel($Text, 0, 0, $Width, $Height, BitOR($SS_CENTER, $SS_NOTIFY, $SS_CENTERIMAGE))
    GUICtrlSetBkColor($idLabel, $Color)
    GUICtrlSetColor($idLabel, $fColor)
    GUICtrlSetFont($idLabel, $fSize, $fWeight, 0, $fName)

    Local $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, $Width, $Height, $Corner, $Corner)
    _WinAPI_SetWindowRgn($hChGUI, $hRgn)
    GUISetState()
    Return $idLabel
EndFunc   ;==>_CreateButton

; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
; Name...........: ColorLight()
; Description....: Returns a new color that is a combination of the $HexColor plus the amount of $Lightness it adds to all three RGB channels.
; Syntax.........: ColorLight($HexColor [, $Lightness [,$output]])
; Parameters.....: $HexColor    - The start color to be combined.
;                  $Lightness   - The amount it adds to all three RGB channels. Negative number to subtract (darker)
;                  $output      - Optional: The format of the output string:
;                                     0 = "0x" followed by the hexadecimal value of the new color (default)
;                                     1 = "#" followed by the hexadecimal value of the new color
;                                     2 = an array containing the red, green and blue values of the new color
; Return values..: The new color as a string or an array.
; Author ........: ioa747
; Notes .........:
;--------------------------------------------------------------------------------------------------------------------------------
Func ColorLight($HexColor, $Lightness = 0, $sOutput = 0)

    If StringLeft($HexColor, 1) = "#" Then $HexColor = StringReplace($HexColor, "#", "0x")

    Local $sHexColor = Hex($HexColor, 6)
    ;ConsoleWrite("$sHexColor=" & $sHexColor & @CRLF)

    Local $aSplit = StringSplit($sHexColor, "")
    Local $aRGB[3]

    If $aSplit[0] = 6 Then
        $aRGB[0] = Dec($aSplit[1] & $aSplit[2], 0)
        $aRGB[1] = Dec($aSplit[3] & $aSplit[4], 0)
        $aRGB[2] = Dec($aSplit[5] & $aSplit[6], 0)
        ;ConsoleWrite(StringFormat("aRGB(%d,%d,%d)", $aRGB[0], $aRGB[1], $aRGB[2]) & @CRLF)
    Else
        ConsoleWrite("Something wrong $aSplit[0]=" & $aSplit[0] & @CRLF)
        Return SetError(1, 0, -1)
    EndIf

    Local $aNewRGB[] = [$aRGB[0] + $Lightness, $aRGB[1] + $Lightness, $aRGB[2] + $Lightness]

    If $aNewRGB[0] < 0 Then $aNewRGB[0] = 0
    If $aNewRGB[0] > 255 Then $aNewRGB[0] = 255
    If $aNewRGB[1] < 0 Then $aNewRGB[1] = 0
    If $aNewRGB[1] > 255 Then $aNewRGB[1] = 255
    If $aNewRGB[2] < 0 Then $aNewRGB[2] = 0
    If $aNewRGB[2] > 255 Then $aNewRGB[2] = 255

    ;ConsoleWrite(StringFormat("aNewRGB(%d,%d,%d)", $aNewRGB[0], $aNewRGB[1], $aNewRGB[2]) & @CRLF)

    Local $sColor

    ;$sOutput:  0:="0x" | 1:="#" | 2:=aRGB[R,G,B]
    Switch $sOutput
        Case 0, 1
            $sColor = ($sOutput = 1 ? "#" : "0x")
            $sColor &= Hex(String($aNewRGB[0]), 2)
            $sColor &= Hex(String($aNewRGB[1]), 2)
            $sColor &= Hex(String($aNewRGB[2]), 2)
            ;ConsoleWrite("$sColor=" & $sColor & @CRLF & @CRLF)

        Case 2
            $sColor = $aNewRGB

    EndSwitch

    Return $sColor

EndFunc   ;==>ColorLight

 

have fun  :)
Thank you very much 

 

Edited by ioa747

I know that I know nothing

  • 9 months later...
Posted

Another approach (improved), in the collection with colored buttons,
with 3D appearance, and toggle capability

; https://www.autoitscript.com/forum/topic/211721-round-buttons/
;----------------------------------------------------------------------------------------
; Title...........: 3DRectButton.au3
; Description.....: Creates colored buttons, with 3D appearance, and toggle capability.
; AutoIt Version..: 3.3.18.0   Author: ioa747           Script Version: 0.1
; Note............: Testet in Windows 11 Pro 24H2       Date:9/11/2025
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <WindowsStylesConstants.au3>
#include <WinAPIGdi.au3>

; maps to hold buttons data
Global $mButtons[], $mBtn[]

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 270)
    GUISetFont(10, 800)

    ; Create a button control.
    Local $idButton_1 = _Button("Darck", 20, 20, 85, 30, 0xFF720E)
    GUICtrlSetTip(-1, "Long press to togle")
    Local $idButton_2 = _Button("Button 2", 20, 70, 85, 30, 0x36BB48)
    Local $idButton_3 = _Button("Button 3", 20, 120, 85, 30, 0x3BADFF)
    Local $idButton_4 = _Button("Button 4", 20, 170, 85, 30, 0xD980FF)

    Local $idButton_5 = GUICtrlCreateButton("Button 5", 20, 220, 85, 30)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idButton_1
                ConsoleWrite("$idButton_1 Down" & @CRLF)

            Case $idButton_2
                ConsoleWrite("$idButton_2 Down" & @CRLF)

            Case $idButton_3
                ConsoleWrite("$idButton_3 Down" & @CRLF)

            Case $idButton_4
                ConsoleWrite("$idButton_4 Down" & @CRLF)

            Case $mButtons[$idButton_1].event
                ConsoleWrite("$idButton_1 Up" & @CRLF)
                If $mButtons[$idButton_1].togle Then
                    GUISetBkColor(0x33373A, $hGUI)
                Else
                    GUISetBkColor(0xF0F0F0, $hGUI)
                EndIf
                ConsoleWrite("$mButtons[$idButton_1].togle=" & $mButtons[$idButton_1].togle & @CRLF)

            Case $mButtons[$idButton_2].event
                ConsoleWrite("$idButton_2 Up" & @CRLF)
                ConsoleWrite("$mButtons[$idButton_2].togle=" & $mButtons[$idButton_2].togle & @CRLF)

            Case $mButtons[$idButton_3].event
                ConsoleWrite("$idButton_3 Up" & @CRLF)

            Case $mButtons[$idButton_4].event
                ConsoleWrite("$idButton_4 Up" & @CRLF)

            Case $idButton_5
                ConsoleWrite("$idButton_5 Up" & @CRLF)

        EndSwitch
        _Hover($hGUI)
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)

EndFunc   ;==>Example
;---------------------------------------------------------------------------------------
Func _Hover($hGUI, $iHighlight = 20)
    Local Static $iActive

    If Not WinActive($hGUI) Then Return SetError(1, 0, False)

    Local $ActiveCtrl, $mBtn
    Local $aCtrl = GUIGetCursorInfo($hGUI)
    $ActiveCtrl = IsArray($aCtrl) ? $aCtrl[4] : 0

    If Not (MapExists($mButtons, $ActiveCtrl) Or $ActiveCtrl = 0) Then Return

    If $iActive <> $ActiveCtrl Then

        ; Reset Highlight
        If $iActive > 0 Then
            $mBtn = $mButtons[$iActive]
            GUICtrlSetBkColor($mBtn.id, $mBtn.BkColor)
            $iActive = 0
            Return SetError(2, 0, False)
        EndIf

        If Not $ActiveCtrl Then Return

        ; Highlight
        $iActive = $ActiveCtrl
        $mBtn = $mButtons[$iActive]
        GUICtrlSetBkColor($mBtn.id, ColorLight($mBtn.BkColor, $iHighlight))

    EndIf

    ; Click efect
    If $aCtrl[2] And $ActiveCtrl Then
        $mBtn = $mButtons[$iActive]

        ; Move the button based on current toggle state
        If Not $mBtn.togle Then
            GUICtrlSetPos($mBtn.id, $mBtn.X + 2, $mBtn.Y + 2) ; If not toggled, move down
        Else
            GUICtrlSetPos($mBtn.id, $mBtn.X, $mBtn.Y)         ; If toggled, move up
        EndIf

        Local $iStartTime = TimerInit()
        Do
            $aCtrl = GUIGetCursorInfo($hGUI)
            Sleep(10)
            If TimerDiff($iStartTime) > 1500 Then ToolTip("Togle Locked")
        Until $aCtrl[2] = 0

        ; *** Long press > 1.5 sec -> enable togle
        If TimerDiff($iStartTime) > 1500 Then
            $mBtn.togle = True
        Else
            $mBtn.togle = False
        EndIf

        ToolTip("")

        ; If is toggled, stay down
        If $mBtn.togle Then
            GUICtrlSetPos($mBtn.id, $mBtn.X + 2, $mBtn.Y + 2)
        Else
            GUICtrlSetPos($mBtn.id, $mBtn.X, $mBtn.Y)
        EndIf

        $mButtons[$mBtn.id] = $mBtn     ; Update the button's data in the global map
        GUICtrlSendToDummy($mBtn.event) ; Send the dummy event to trigger the Up event
    EndIf

    Sleep(10)

EndFunc   ;==>_Hover
;---------------------------------------------------------------------------------------
Func _Button($Text, $Left, $Top, $Width, $Height, $hBkColor = 0xF0F0F0, $hTxtColor = 0x000000, $iShadow = 30)

    Local $hShColor = ColorLight($hBkColor, -$iShadow)

    Local $idEvent = GUICtrlCreateDummy()

    Local $idShadow = GUICtrlCreateLabel("", $Left - 1, $Top - 1, $Width + 4, $Height + 4)
    GUICtrlSetBkColor(-1, $hShColor)
    GUICtrlSetState(-1, $GUI_DISABLE)

    Local $id = GUICtrlCreateLabel($Text, $Left, $Top, $Width, $Height, BitOR($SS_CENTERIMAGE, $SS_CENTER))
    GUICtrlSetBkColor(-1, $hBkColor)
    GUICtrlSetColor(-1, $hTxtColor)

    $mBtn.id = $id
    $mBtn.event = $idEvent
    $mBtn.text = $Text
    $mBtn.X = $Left
    $mBtn.Y = $Top
    $mBtn.W = $Width
    $mBtn.H = $Height
    $mBtn.BkColor = $hBkColor
    $mBtn.TxtColor = $hTxtColor
    $mBtn.shadow = $idShadow
    $mBtn.ShColor = $hShColor
    $mBtn.togle = False

    $mButtons[$id] = $mBtn
    Return $id
EndFunc   ;==>_Button
;--------------------------------------------------------------------------------------------------------------------------------
Func ColorLight($HexColor, $Lightness = 30)
    Local $iHue, $iLuminance, $iSaturation
    _WinAPI_ColorRGBToHLS($HexColor, $iHue, $iLuminance, $iSaturation)
    Local $hColor = Hex(_WinAPI_ColorHLSToRGB($iHue, $iLuminance + $Lightness, $iSaturation), 6)
    Return '0x' & $hColor
EndFunc   ;==>ColorLight
;---------------------------------------------------------------------------------------

 

have fun  :)
Thank you very much 

 

I know that I know nothing

Posted

Hey ioa, just a suggestion - have you tried giving ownerdrawn buttons a go?

WM_DRAWITEM triggers, and will tell you the button state so you can draw it accordingly. Basically you can have your button react to changes in focus, checked, depressed, greyed out states etc etc - without the need for manufacturing events via those dummy controls.

Posted

Perhaps a starting point with the ownerdrawn approach if you wanted to have a crack! take or leave it ;)

#include <GUIConstants.au3>
#include <guibutton.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>
#include <WindowsSysColorConstants.au3>
#include <WinAPIGdiDC.au3>
#include <FrameConstants.au3>
#include <SendMessage.au3>

_WinAPI_SetUDFColorMode($UDF_RGB) ;So _WinAPI_RGB works as expected.
;By default the UDF swaps the colour values around - presumably so you can represent a RGB value with hex notation without endian issues. i.e. 0x00RRGGBB

Global Const $ODT_MENU = 1
Global Const $ODT_LISTBOX = 2
Global Const $ODT_COMBOBOX = 3
Global Const $ODT_BUTTON = 4
Global Const $ODT_STATIC = 5

Global Const $ODA_DRAWENTIRE = 1
Global Const $ODA_FOCUS = 2
Global Const $ODA_SELECT = 4

Global Const $ODS_SELECTED = 0x0001
Global Const $ODS_GRAYED = 0x0002
Global Const $ODS_DISABLED = 0x0004
Global Const $ODS_CHECKED = 0x0008
Global Const $ODS_FOCUS = 0x0010
Global Const $ODS_DEFAULT = 0x0020
Global Const $ODS_COMBOBOXEDIT = 0x1000
Global Const $ODS_HOTLIGHT = 0x0040
Global Const $ODS_INACTIVE = 0x0080
Global Const $ODS_NOACCEL = 0x0100
Global Const $ODS_NOFOCUSRECT = 0x0200

Global $tagDRAWITEMSTRUCT = StringFormat("struct;uint ctlType;uint CtlID;uint itemID;uint itemAction;uint itemState;hwnd hwndItem;handle hDC;%s;ulong_ptr itemData;endstruct", $tagRect)

Local $hGUI = GUICreate("", 200, 50)
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
Local $hBtn = _GUICtrlButton_Create($hGUI, "test", 10, 10, 80, 25, $BS_OWNERDRAW)
Local $idBtn2 = GUICtrlCreateButton("Disable", 100, 10, 80, 25)

GUISetState()
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $idBtn2
            If BitAnd(WinGetState($hBtn), $WIN_STATE_ENABLED) Then
                WinSetState($hBtn, "", @SW_DISABLE)
                GUICtrlSetData($idBtn2, "Enable")
            Else
                WinSetState($hBtn, "", @SW_ENABLE)
                GUICtrlSetData($idBtn2, "Disable")
            EndIf

        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_DRAWITEM($hWnd, $iMsg, $wParam, $lParam)
    Local $tDRAWITEMSTRUCT = DllStructCreate($tagDRAWITEMSTRUCT, $lParam)
    Local $hDC = $tDRAWITEMSTRUCT.hDC
    Local $tWinRect = DllStructCreate($tagRect, DllStructGetPtr($tDRAWITEMSTRUCT, "Left"))
    Local $iTextLen = _SendMessage($tDRAWITEMSTRUCT.hwndItem, $WM_GETTEXTLENGTH)
    Local $tText = DllStructCreate(StringFormat("wchar text[%d]", $iTextLen + 1))
    _SendMessage($tDRAWITEMSTRUCT.hwndItem, $WM_GETTEXT, DllStructGetSize($tText), $tText, 0, "wparam", "struct*")

    Local $iFaceCol =  BitAND($tDRAWITEMSTRUCT.itemState, $ODS_DISABLED) ? _WinAPI_RGB(0xE0, 0xE0, 0xE0) : _WinAPI_RGB(0xE0, 0xE0, 0xFF)

    Switch $tDRAWITEMSTRUCT.ctlType
        Case $ODT_BUTTON
            If BitAND($tDRAWITEMSTRUCT.itemAction, $ODA_DRAWENTIRE) Then
                If BitAND($tDRAWITEMSTRUCT.itemState, $ODS_SELECTED) Then
                    _WinAPI_DrawFrameControl($hDC, $tWinRect, $DFC_BUTTON, BitOR($DFCS_BUTTONPUSH, $DFCS_PUSHED))
                    $iFaceCol = _WinAPI_RGB(0xC0, 0xC0, 0xEF)
                Else
                    _WinAPI_DrawFrameControl($hDC, $tWinRect, $DFC_BUTTON, $DFCS_BUTTONPUSH)
                EndIf

                _WinAPI_InflateRect($tWinRect, -3, -3)
                $hSelBrush = _WinAPI_CreateSolidBrush($iFaceCol)
                _WinAPI_SelectObject($hDC, $hSelBrush)
                _WinAPI_FillRect($hDC, $tWinRect, $hSelBrush)
                _WinAPI_DeleteObject($hSelBrush)
                _WinAPI_InflateRect($tWinRect, 3, 3)
                _WinAPI_SetBkColor($hDC, $iFaceCol)
                _WinAPI_DrawText($hDC, $tText.Text, $tWinRect, BitOR($DT_CENTER, $DT_VCENTER, $DT_SINGLELINE))
            EndIf

            If BitAND($tDRAWITEMSTRUCT.itemState, $ODS_FOCUS) Then
                _WinAPI_InflateRect($tWinRect, -3, -3)
                $hSelBrush = _WinAPI_GetStockObject($HOLLOW_BRUSH)
                $hSelPen = _WinAPI_CreatePen($PS_DOT, 1, _WinAPI_RGB(0, 0xAA, 0xAA))
                _WinAPI_SelectObject($hDC, $hSelPen)
                _WinAPI_SelectObject($hDC, $hSelBrush)
                _WinAPI_Rectangle($hDC, $tWinRect)
                _WinAPI_DeleteObject($hSelPen)
                _WinAPI_DeleteObject($hSelBrush)
            EndIf
    EndSwitch

    Return 1
EndFunc   ;==>WM_DRAWITEM

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...