Jump to content
Stormgrade

Request UDF GDIpProgress.au3

Recommended Posts

Here is another one from : https://github.com/Universal-Rom-Tools/Universal-XML-Scraper/blob/master/Include/_GDIpProgress.au3

I don't know if this version is newer or modified, at least the code is longer ;).

#cs ----------------------------------------------------------------------------

    AutoIt Version: 3.2.12.0
    Author:         Prog@ndy
    after Script from nobbe ( 2008 in http://www.autoitscript.com/forum/index.php?s=&showtopic=64703&view=findpost&p=485031 )

    Script Function:  A UDF for colored Progressbars with GDIPlus

    Remarks: Theres an example from Line 22 to line 112 ( between the first #Region - #Endregion Tags

#ce ----------------------------------------------------------------------------

#include-once
#include <GuiConstants.au3>
#include <WIndowsConstants.au3>
#include <EditConstants.au3>
#include <WinApi.au3>
#include <GdiPlus.au3>

Global $_Progress_ahCallBack[3] = [-1, -1, 0], $_Progress_Bars[1][15] = [[-1]], $iPercent = 0;

#EndRegion EXAMPLE
;##################################################

;-------------------------------------------------------------------
#Region Colored Progressbar
;===============================================================================
;
; Function Name:   _ProgressCreate
; Description::    Creates a GDIplus Progressbar
; Parameter(s):    $x     : left
;                  $y     : top
;                  $w     : width
;                  $h     : height
;                  $Col     : [Optional] Top color of the foreground gradient
;                  $GradCol : [Optional] Bottom color of the foreground gradient
;                  $BG      : [Optional] Top color of the background gradient
;                  $GradBG  : [Optional] Bottom color of the background gradient
; Requirement(s):  GDIplus
; Return Value(s): Success: ID of Progressbar, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _ProgressCreate($x, $y, $w = 204, $h = 24, $Col = 0xFFFF00, $GradCol = 0x00FF00, $BG = 0xAAAA00, $GradBG = 0xFF0000)
    __CheckForGDIPlus()
    $ID = UBound($_Progress_Bars)
    ReDim $_Progress_Bars[$ID + 1][15]
    $_Progress_Bars[$ID][0] = GUICtrlCreateLabel("", $x, $y, $w, $h)
    GUICtrlSetStyle(-1,0)
    GUICtrlSetBkColor($_Progress_Bars[$ID][0], -2) ; $GUI_BKCOLOR_TRANSPARENT = -2
    If @error Then Return SetError(@error, @extended, 0)
    If $Col = -1 Then $Col = 0xFFFF00
    If $BG = -1 Then $BG = 0xAAAA00
    If $GradCol = -1 Then $GradCol = 0x00FF00
    If $GradBG = -1 Then $GradBG = 0xFF0000
    _GDIPlus_Startup()
    Local $graphic = _GDIPlus_GraphicsCreateFromHWND(GUICtrlGetHandle($_Progress_Bars[$ID][0]))
    Local $bitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $graphic)
    Local $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

    Local $bmpfront = _GDIPlus_BitmapCreateFromGraphics($w, $h, $graphic)
    _CreateGradientImg($bmpfront, $w - 1, $h - 1, $Col, $GradCol)
    $_Progress_Bars[$ID][11] = _GDIPlus_ImageGetWidth($bmpfront)
    $_Progress_Bars[$ID][12] = _GDIPlus_ImageGetHeight($bmpfront)

    Local $bmpBack = _GDIPlus_BitmapCreateFromGraphics($w, $h, $graphic)
    _CreateGradientImg($bmpBack, $w - 1, $h - 1, $BG, $GradBG)
    $_Progress_Bars[$ID][13] = _GDIPlus_ImageGetWidth($bmpBack)
    $_Progress_Bars[$ID][14] = _GDIPlus_ImageGetHeight($bmpBack)

    $_Progress_Bars[$ID][1] = $w
    $_Progress_Bars[$ID][2] = $h

    $_Progress_Bars[$ID][3] = $graphic
    $_Progress_Bars[$ID][4] = $bitmap
    $_Progress_Bars[$ID][5] = $backbuffer
    $_Progress_Bars[$ID][6] = $bmpfront
    $_Progress_Bars[$ID][7] = $bmpBack
    $_Progress_Bars[$ID][8] = 0
    $_Progress_Bars[$ID][9] = 1
    $_Progress_Bars[$ID][10] = "Arial|10|1|0xFF000000|0"
    _ProgressRefresh($ID, 0)
    _Progress_CallBack_Init()
    Return SetError(0, 0, $ID)
EndFunc   ;==>_ProgressCreate

;===============================================================================
;
; Function Name:   _ProgressDelete
; Description::    Deletes a GDI+ Progressbar
; Parameter(s):    $ID      : ID of Progressbar
; Requirement(s):  GDIplus
; Return Value(s): Sucess: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _ProgressDelete(ByRef $ID)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    If $_Progress_Bars[$ID][0] = -1 Then Return SetError(-1,0,0)
    _Progress_CallBack_Free()
    Local $temp[9],$i
    FoR $i = 0 To 8
        $temp[$i] = $_Progress_Bars[$ID][$i]
    Next
    $_Progress_Bars[$ID][0] = -1
    Local $ret = GUICtrlDelete($temp[0])
    If @error Then Return SetError(1,0,0)
    $_Progress_Bars[$ID][1] = -1
    $_Progress_Bars[$ID][2] = -1

    $_Progress_Bars[$ID][3] = -1
    _GDIPlus_GraphicsDispose($temp[3])
    Local $error = @error
    $_Progress_Bars[$ID][4] = -1
    _WinAPI_DeleteObject($temp[4])
    Local $error = @error
    $_Progress_Bars[$ID][5] = -1
    _GDIPlus_GraphicsDispose($temp[5])
    Local $error = @error
    $_Progress_Bars[$ID][6] = -1
    _WinAPI_DeleteObject($temp[6])
    Local $error = @error
    _GDIPlus_ImageDispose($temp[6])
    Local $error = @error
    $_Progress_Bars[$ID][7] = -1
    _WinAPI_DeleteObject($temp[7])
    Local $error = @error
    _GDIPlus_ImageDispose($temp[7])
    $_Progress_Bars[$ID][8] = -1


    _GDIPlus_Shutdown()
    Return SetError($error, 0, $error=0)
EndFunc   ;==>_ProgressDelete

;===============================================================================
;
; Function Name:   _ProgressSetColors(
; Description::    Sets gradients as foreground and background
; Parameter(s):    $ID      : ID of Progressbar
;                  $Col     : Top color of the foreground gradient
;                  $GradCol : Bottom color of the foreground gradient
;                  $BG      : Top color of the background gradient
;                  $GradBG  : Bottom color of the background gradient
;             If $Col or $GradCol is -1, the foreground gradient isn't changed
;             If $BG or $GradBG is -1, the background gradient isn't changed
; Requirement(s):  Winapi.au3, GDIplus
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _ProgressSetColors(ByRef $ID, $Col = -1, $GradCol = -1, $BG = -1, $GradBG = -1)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    If Execute($Col) > -1 And Execute($GradCol) > -1 Then
        _WinAPI_DeleteObject($_Progress_Bars[$ID][6])
        _GDIPlus_ImageDispose($_Progress_Bars[$ID][6])
        $_Progress_Bars[$ID][6] = _GDIPlus_BitmapCreateFromGraphics($_Progress_Bars[$ID][1], $_Progress_Bars[$ID][2], $_Progress_Bars[$ID][3])
        _CreateGradientImg($_Progress_Bars[$ID][6], $_Progress_Bars[$ID][1] - 1, $_Progress_Bars[$ID][2] - 1, $Col, $GradCol)
        $_Progress_Bars[$ID][11] = $_Progress_Bars[$ID][1]
        $_Progress_Bars[$ID][12] = $_Progress_Bars[$ID][2]
    EndIf
    If Execute($BG) > -1 And Execute($GradBG) > -1 Then
        _WinAPI_DeleteObject($_Progress_Bars[$ID][7])
        _GDIPlus_ImageDispose($_Progress_Bars[$ID][7])
        $_Progress_Bars[$ID][7] = _GDIPlus_BitmapCreateFromGraphics($_Progress_Bars[$ID][1], $_Progress_Bars[$ID][2], $_Progress_Bars[$ID][3])
        _CreateGradientImg($_Progress_Bars[$ID][7], $_Progress_Bars[$ID][1] - 1, $_Progress_Bars[$ID][2] - 1, $BG, $GradBG)
        $_Progress_Bars[$ID][13] = $_Progress_Bars[$ID][1]
        $_Progress_Bars[$ID][14] = $_Progress_Bars[$ID][2]
    EndIf
;~  _ProgressSet($ID, $_Progress_Bars[$ID][8])
    Return SetError(@error, 0, @error = 0)
EndFunc   ;==>_ProgressSetColors


;===============================================================================
;
; Function Name:   _ProgressSetImages(
; Description::    Sets images as foreground and background by Path
; Parameter(s):    $ID : ID of Progressbar
;                  $ForeBmp : Path to image , empty String "" To leave the old
;                             The foreground image
;                  $BackBmp : [Optional] Path to image , empty String "" To leave the old
;                             The background image
; Requirement(s):  Winapi.au3, GDIplus
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _ProgressSetImages(ByRef $ID, $ForeBmp = "", $backBMP = "")
    Local $bmp = ""
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    If GUICtrlGetHandle($_Progress_Bars[$ID][0]) = 0 Then Return SetError(2, 0, 0)
    If $ForeBmp <> "" And FileExists($ForeBmp) Then
        $bmp = _GDIPlus_ImageLoadFromFile($ForeBmp)
        If Not @error Then
;~          _WinAPI_DeleteObject($_Progress_Bars[$ID][6])
            _GDIPlus_ImageDispose($_Progress_Bars[$ID][6])
            $_Progress_Bars[$ID][6] = $bmp
            $_Progress_Bars[$ID][11] = _GDIPlus_ImageGetWidth($_Progress_Bars[$ID][6])
            $_Progress_Bars[$ID][12] = _GDIPlus_ImageGetHeight($_Progress_Bars[$ID][6])
        EndIf
    EndIf
    If $backBMP <> "" And FileExists($backBMP) Then
        $bmp = _GDIPlus_ImageLoadFromFile($backBMP)
        If Not @error Then
;~          _WinAPI_DeleteObject($_Progress_Bars[$ID][7])
            _GDIPlus_ImageDispose($_Progress_Bars[$ID][7])
            $_Progress_Bars[$ID][7] = $bmp
            $_Progress_Bars[$ID][13] = _GDIPlus_ImageGetWidth($_Progress_Bars[$ID][7])
            $_Progress_Bars[$ID][14] = _GDIPlus_ImageGetHeight($_Progress_Bars[$ID][7])
        EndIf
    EndIf
;~  _ProgressSet($ID, $_Progress_Bars[$ID][8])
    Return SetError(@error, 0, @error = 0)
EndFunc   ;==>_ProgressSetImages

;===============================================================================
;
; Function Name:   _ProgressSetHBitmaps(
; Description::    Sets previously loaded GDIplus Images / bitmaps as foreground and background
; Parameter(s):    $ID : ID of Progressbar
;                  $ForeBmp : Handle to GDIplus -image or -bitmap , -1 To leave the old
;                             The foreground image
;                  $BackBmp : [Optional] Handle to GDIplus -image or -bitmap , -1 To leave the old
;                             The background image
; Requirement(s):  Winapi.au3, GDIplus
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _ProgressSetHBitmaps(ByRef $ID, $ForeBmp = -1, $backBMP = -1)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    If GUICtrlGetHandle($_Progress_Bars[$ID][0]) = 0 Then Return SetError(2, 0, 0)
    If $ForeBmp > -1 And _GDIPlus_ImageGetHeight($ForeBmp) Then
;~      _WinAPI_DeleteObject($_Progress_Bars[$ID][6])
        _GDIPlus_ImageDispose($_Progress_Bars[$ID][6])
        $_Progress_Bars[$ID][6] = $ForeBmp
        $_Progress_Bars[$ID][11] = _GDIPlus_ImageGetWidth($_Progress_Bars[$ID][6])
        $_Progress_Bars[$ID][12] = _GDIPlus_ImageGetHeight($_Progress_Bars[$ID][6])
    EndIf
    If $backBMP > -1 And _GDIPlus_ImageGetHeight($backBMP) Then
;~      _WinAPI_DeleteObject($_Progress_Bars[$ID][7])
        _GDIPlus_ImageDispose($_Progress_Bars[$ID][7])
        $_Progress_Bars[$ID][7] = $backBMP
        $_Progress_Bars[$ID][13] = _GDIPlus_ImageGetWidth($_Progress_Bars[$ID][7])
        $_Progress_Bars[$ID][14] = _GDIPlus_ImageGetHeight($_Progress_Bars[$ID][7])
    EndIf
;~  _ProgressSet($ID, $_Progress_Bars[$ID][8])
    Return SetError(@error, 0, @error = 0)
EndFunc   ;==>_ProgressSetHBitmaps

;===============================================================================
;
; Function Name:   _ProgressSetText(
; Description::    Sets the text to be shown
; Parameter(s):    $ID : ID of Progressbar
;                  $text:  -> TRUE : Show percent
;                          -> A string to be shown, %P% is replaced with Percentage
; Requirement(s):  This UDf
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _ProgressSetText(ByRef $ID, $text = True)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    $_Progress_Bars[$ID][9] = $text
;~  _ProgressSet($ID, $_Progress_Bars[$ID][8])
    Return SetError(@error, 0, @error = 0)
EndFunc   ;==>_ProgressSetText

;===============================================================================
;
; Function Name:   _ProgressSetFont()
; Description::    Sets the Font and Color of the Text of the Progressbar
; Parameter(s):    $ID : ID of Progressbar
;                  $Font      : Name of the font (empty String "" to do not change)
;                  $size      : [Optional] size of the font ( 0 or negative to leave the old)
;                  $Styles    : [Optional] The style of the typeface. Can be a combination of the following:
;                                  0 - Normal weight or thickness of the typeface
;                                  1 - Bold typeface
;                                  2 - Italic typeface
;                                  4 - Underline
;                                  8 - Strikethrough
;                                  ( -1, negative to leave the old)
;                  $ARGBcolor : [Optional] the color of the font, can be RGB or ARGB (depending on  $isARGB)
;                                  (empty String "" to do not change)
;                  $InverseColor: [Optional] should the color be inversed when the bar is under the text?
;                  $isARGB    : [Optional] Sets, whether $ARGBcolor is RGB (False, default) or ARGB (True)
; Requirement(s):  This UDF
; Return Value(s): Success: 1, Error: 0
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _ProgressSetFont(ByRef $ID, $Font, $size = Default, $Styles = Default, $ARGBcolor = Default, $InverseColor=-1, $isARGB = False)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    Local $array = StringSplit($_Progress_Bars[$ID][10], "|")
    If $Font <> "" And IsString($Font) And $Font <> Default Then $array[1] = $Font
    $size = Number($size)
    If $size > 0 And $size <> Default Then $array[2] = $size
    $Styles = Number($Styles)
    If $Styles > -1 And $Styles <> Default Then $array[3] = BitAND($Styles, 15)
    If Not $isARGB Then $ARGBcolor = "0xFF" & Hex($ARGBcolor, 6)
    If Not ($ARGBcolor == "") And Not ($ARGBcolor == Default) Then $array[4] = "0x" & Hex($ARGBcolor, 8)
    If $InverseColor > 0 Then $array[5] = "1"
    If $InverseColor = 0 Then $array[5] = "0"
    $_Progress_Bars[$ID][10] = $array[1] & "|" & $array[2] & "|" & $array[3] & "|" & $array[4] & "|" & $array[5]
;~  _ProgressSet($ID, $_Progress_Bars[$ID][8])
    Return SetError(@error, 0, @error = 0)
EndFunc   ;==>_ProgressSetFont

;===============================================================================
;
; Function Name:   _ProgressSet()
; Description::    Sets the percentage of the Progressbar
; Parameter(s):    $ID : ID of Progressbar
;                  $prc The percentage to set
; Requirement(s):  This UDF :)
; Return Value(s): If Progressbar odes not Exist: @error is set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _ProgressSet(ByRef $ID, $prc)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    If $prc > 100 Then $prc = 100
    If $prc < 0 Then $prc = 0
    $_Progress_Bars[$ID][8] = $prc
    Return 1
EndFunc   ;==>_ProgressSet
Func _ProgressGet(ByRef $ID)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    Return _WinAPI_LoWord($_Progress_Bars[$ID][8])
EndFunc
;===============================================================================
;
; Function Name:   _ProgressMarquee()
; Description::    Sets the
; Parameter(s):    $ID : ID of Progressbar
;                  $speed : The speed of the Marquee: 1 to 10, smaller as 1 turns it off
;                  $makeSmallFront : Crop the Front image to 1/10 of its former width
;                         If it was created by _ProgressSetColors, this is 1/10 of Progress Width :)
;                         If this is set to -1 and $speed is set to < 0 then the Front image size is
;                             set to the width of the Progressbar
; Requirement(s):  WinAPI
; Return Value(s): If Progressbar does not Exist: @error is set to 1
; Author(s):       Prog@ndy
;
;===============================================================================
;
Func _ProgressMarquee(ByRef $ID, $speed = 2, $makeSmallFront = 1)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    If $speed < 0 Then
        $_Progress_Bars[$ID][8] = _WinAPI_LoWord($_Progress_Bars[$ID][8])
        If $makeSmallFront = -1 Then $_Progress_Bars[$ID][11] = $_Progress_Bars[$ID][1]
        Return 1
    EndIf
    If $speed > 10 Then $speed = 10
    If $speed < 1 Then $speed = 1
    $_Progress_Bars[$ID][8] = _WinAPI_MakeLong(_WinAPI_LoWord($_Progress_Bars[$ID][8]), Number($speed))
    If $makeSmallFront Then $_Progress_Bars[$ID][11] = Int($_Progress_Bars[$ID][11] / 10)
    Return 1
EndFunc   ;==>_ProgressMarquee

; Author(s):       Prog@ndy
Func _ProgressRefresh(ByRef $ID, $prc = Default)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    If $_Progress_Bars[$ID][1] < 1 Then Return SetError(2, 0, 0)
    Local $bar_height = $_Progress_Bars[$ID][2]
    Local $bar_width = $_Progress_Bars[$ID][1]
    If $prc = Default Then $prc = $_Progress_Bars[$ID][8]
    If $_Progress_Bars[$ID][8] > 65535 Then Return _ProgressRefreshMarquee($ID)
    If $prc > 100 Then $prc = 100
    If $prc < 0 Then $prc = 0
    $_Progress_Bars[$ID][8] = $prc
;~     $iPercent = $prc
;~ ConsoleWrite($iPercent & @CRLF)
;~     GUICtrlSetData($Status_Label, $prc & "%")
    Local $position_in_bar = Int(($bar_width) / 100 * $prc) ;; or we move out the bar
    If $prc = 0 Then $position_in_bar = 0
    _GDIPlus_GraphicsClear($_Progress_Bars[$ID][5], 0xFFFFFFFF)

;~      ; draw grey bar to right side
;~  _GDIPlus_GraphicsDrawImageRectRect($_Progress_Bars[$ID][5], $_Progress_Bars[$ID][7], Int(($_Progress_Bars[$ID][13] / 100) * $prc), 0, Int(($_Progress_Bars[$ID][13] / 100) * (100 - $prc)), $_Progress_Bars[$ID][14], _
;~          $position_in_bar , _
;~          0, _
;~          $bar_width - ($position_in_bar ), _
;~          $bar_height);
;~
        ; draw grey bar to right side
    _GDIPlus_GraphicsDrawImageRectRect($_Progress_Bars[$ID][5], $_Progress_Bars[$ID][7], 0 , 0, $_Progress_Bars[$ID][13] , $_Progress_Bars[$ID][14], _
            0 , _
            0, _
            $bar_width , _
            $bar_height);

    ;; draw blue bar from left
    If $position_in_bar > 0 Then _GDIPlus_GraphicsDrawImageRectRect($_Progress_Bars[$ID][5], $_Progress_Bars[$ID][6], _
            0, 0, Int(($_Progress_Bars[$ID][11] / 100) * $prc), $_Progress_Bars[$ID][12], _
            0, _
            0, _
            $position_in_bar, _
            $bar_height)


    If Not IsString($_Progress_Bars[$ID][9]) And $_Progress_Bars[$ID][9] = True Then
        _DrawStringCenter($_Progress_Bars[$ID][5], $prc & "%", $bar_width, $bar_height, $_Progress_Bars[$ID][10])
        If $position_in_bar Then _DrawStringCenter($_Progress_Bars[$ID][5], $prc & "%", $bar_width, $bar_height, $_Progress_Bars[$ID][10], $position_in_bar)
    ElseIf StringLen($_Progress_Bars[$ID][9]) > 0 Then
        _DrawStringCenter($_Progress_Bars[$ID][5], StringReplace($_Progress_Bars[$ID][9], "%P%", $prc), $bar_width, $bar_height, $_Progress_Bars[$ID][10])
        If $position_in_bar Then _DrawStringCenter($_Progress_Bars[$ID][5], StringReplace($_Progress_Bars[$ID][9], "%P%", $prc), $bar_width, $bar_height, $_Progress_Bars[$ID][10], $position_in_bar)
    EndIf
;~  _GDIPlus_GraphicsDrawString($_Progress_Bars[$ID][5],$prc & " %",Ceiling(($bar_width/2)-15),Ceiling(($bar_height/2)-5))
    _GDIPlus_GraphicsDrawImage($_Progress_Bars[$ID][3], $_Progress_Bars[$ID][4], 0, 0)

EndFunc   ;==>_ProgressRefresh

; Author(s):       Prog@ndy
Func _ProgressRefreshMarquee(ByRef $ID, $prc = Default)
    If Not IsArray($_Progress_Bars) Or UBound($_Progress_Bars, 2) <> 15 Or $ID > (UBound($_Progress_Bars)-1) Then Return SetError(1, 0, 0)
    If $_Progress_Bars[$ID][1] < 1 Then Return SetError(2, 0, 0)
    Local $bar_height = $_Progress_Bars[$ID][2]
    Local $bar_width = $_Progress_Bars[$ID][1]
    If $prc = Default Then $prc = _WinAPI_LoWord($_Progress_Bars[$ID][8])
    If $prc > 100 Then $prc = 0
    If $prc < 0 Then $prc = 0
    $_Progress_Bars[$ID][8] = _WinAPI_MakeLong($prc + _WinAPI_HiWord($_Progress_Bars[$ID][8]), _WinAPI_HiWord($_Progress_Bars[$ID][8]))
;~     $iPercent = $prc
;~ ConsoleWrite($iPercent & @CRLF)
;~     GUICtrlSetData($Status_Label, $prc & "%")
    Local $position_in_bar = Int(($bar_width + ($bar_height / $_Progress_Bars[$ID][12] * $_Progress_Bars[$ID][11])) / 100 * $prc) ;; or we move out the bar
    If $prc = 0 Then $position_in_bar = 0
    _GDIPlus_GraphicsClear($_Progress_Bars[$ID][5], 0xFFFFFFFF)
    ; draw grey bar to right side
    _GDIPlus_GraphicsDrawImageRectRect($_Progress_Bars[$ID][5], $_Progress_Bars[$ID][7], 0, 0, $_Progress_Bars[$ID][13], $_Progress_Bars[$ID][14], _
            0, _
            0, _
            $bar_width, _
            $bar_height);
    ;; draw blue bar from left
    If $position_in_bar > 0 Then _GDIPlus_GraphicsDrawImageRectRect($_Progress_Bars[$ID][5], $_Progress_Bars[$ID][6], _
            0, 0, $_Progress_Bars[$ID][11], $_Progress_Bars[$ID][12], _
            $position_in_bar - ($bar_height / $_Progress_Bars[$ID][12] * $_Progress_Bars[$ID][11]), _
            0, _
            $bar_height / $_Progress_Bars[$ID][12] * $_Progress_Bars[$ID][11], _
            $bar_height)
    If (Not IsString($_Progress_Bars[$ID][9])) And $_Progress_Bars[$ID][9] = True Then
        _DrawStringCenter($_Progress_Bars[$ID][5], StringReplace("          ", " ", ".", Mod(@SEC, 5) + 1), $bar_width, $bar_height, $_Progress_Bars[$ID][10])
    ElseIf StringLen($_Progress_Bars[$ID][9]) > 0 Then
        _DrawStringCenter($_Progress_Bars[$ID][5], StringReplace($_Progress_Bars[$ID][9], "%P%", StringReplace("            ", " ", ".", Mod(@SEC, 5) + 1)), $bar_width, $bar_height, $_Progress_Bars[$ID][10])
    EndIf
;~  _GDIPlus_GraphicsDrawString($_Progress_Bars[$ID][5],$prc & " %",Ceiling(($bar_width/2)-15),Ceiling(($bar_height/2)-5))
    _GDIPlus_GraphicsDrawImage($_Progress_Bars[$ID][3], $_Progress_Bars[$ID][4], 0, 0)

EndFunc   ;==>_ProgressRefreshMarquee


; Author(s):       Prog@ndy
Func _DrawStringCenter(ByRef $hGraphic, $sString, $bar_width, $bar_height, $FontFormat = "Arial|12|1|0xFF000000|0", $InverseStart = -1)
    $FontFormat = StringSplit($FontFormat, "|")
    If $InverseStart>-1 And $FontFormat[5]=1 Then
        DLLCall($__g_hGDIPDll, "int", "GdipSetClipRectI", "ptr", $hGraphic, "int", 0, "int", 0, "int", $InverseStart, "int", $bar_height, "int", 0)
        $FontFormat[4]= BitOr(0xFF000000,_InverseColor($FontFormat[4]))
    EndIf
    Local $hBrush = _GDIPlus_BrushCreateSolid($FontFormat[4])
    Local $hFormat = _GDIPlus_StringFormatCreate(0x0400)
    Local $hFamily = _GDIPlus_FontFamilyCreate($FontFormat[1])
    Local $hFont = _GDIPlus_FontCreate($hFamily, $FontFormat[2], $FontFormat[3])
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat)
    DllStructSetData($aInfo[0], "X", Int(($bar_width - DllStructGetData($aInfo[0], "Width")) / 2))
    DllStructSetData($aInfo[0], "Y", Int(($bar_height - DllStructGetData($aInfo[0], "Height")) / 2))
    _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $aInfo[0], $hFormat, $hBrush)
    If $InverseStart>-1 And $FontFormat[5]=1 Then DLLCall($__g_hGDIPDll, "int", "GdipSetClipRectI", "ptr", $hGraphic, "int", 0, "int", 0, "int", $bar_width, "int", $bar_height, "int", 0)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
EndFunc   ;==>_DrawStringCenter

; Modified _Max() Function, directly included
; Author(s):       Jeremy Landes <jlandes at landeserve dot com>
Func _MyMax($nNum1, $nNum2)

    If Number($nNum1) > Number($nNum2) Then
        Return Number($nNum1)
    Else
        Return Number($nNum2)
    EndIf
EndFunc   ;==>_MyMax

#EndRegion Colored Progressbar
;-------------------------------------------------------------------

;-------------------------------------------------------------------
#Region Gradient
;===============================================================================
;
; Function Name:   _Gradient($RGB_Color1 ,$RGB_Color2, $Count)
; Description::    Returns an Array of Gradient Colors
; Parameter(s):    $RGB_Color1 : The Start-Color in RGB Hexadecimal
;                  $RGB_Color2 : The End-Color in RGB Hexadecimal
;                  $Count :      The number of Colors in the Gradient
; Requirement(s):
; Return Value(s): An Array with the Colors
; Author(s):       Prog@ndy
;
;===============================================================================
;

Func _Gradient($RGB_Color1, $RGB_Color2, $Count, $ARGB = False)
    Local $Color1_R, $Color1_G, $Color1_B, $Color2_R, $Color2_G, $Color2_B, $NeuCol_R, $NeuCol_G, $NeuCol_B
    $ARGB = StringLeft("FF", 2 * $ARGB)
    $Color1_R = BitAND(BitShift($RGB_Color1, 16), 0xff)
    $Color1_G = BitAND(BitShift($RGB_Color1, 8), 0xff)
    $Color1_B = BitAND($RGB_Color1, 0xff)

    $Color2_R = BitAND(BitShift($RGB_Color2, 16), 0xff)
    $Color2_G = BitAND(BitShift($RGB_Color2, 8), 0xff)
    $Color2_B = BitAND($RGB_Color2, 0xff)

    $Count -= 1 ; 0-basiert !
    Dim $arColors[$Count + 1], $pos1

    For $i = 0 To $Count
        $pos1 = $Count - $i
        $NeuCol_R = ($Color1_R * $pos1 + $Color2_R * $i) / ($Count)
        $NeuCol_G = ($Color1_G * $pos1 + $Color2_G * $i) / ($Count)
        $NeuCol_B = ($Color1_B * $pos1 + $Color2_B * $i) / ($Count)
        $arColors[$i] = Execute('0x' & $ARGB & Hex($NeuCol_R, 2) & Hex($NeuCol_G, 2) & Hex($NeuCol_B, 2))
    Next
    Return $arColors
EndFunc   ;==>_Gradient


;Hilfsfunktion für doppelten Verlauf
; Author(s):       Prog@ndy
Func _ZwischenGrad($RGB_c, $ARGB = False)
    Local $c_R = BitAND(BitShift($RGB_c, 16), 0xff)
    Local $c_G = BitAND(BitShift($RGB_c, 8), 0xff)
    Local $c_B = BitAND($RGB_c, 0xff)
    $c_R = _MyMax(0, $c_R - 99)
    $c_G = _MyMax(0, $c_G - 99)
    $c_B = _MyMax(0, $c_B - 99)
    If $ARGB Then Return Dec("FF" & Hex($c_R, 2) & Hex($c_G, 2) & Hex($c_B, 2))
    Return Dec(Hex($c_R, 2) & Hex($c_G, 2) & Hex($c_B, 2))
EndFunc   ;==>_ZwischenGrad

; Author(s):       Prog@ndy
Func _CreateGradientImg(ByRef $bmpfront, $w, $h, $startRGB, $endRGB)
    Local $graph_front = _GDIPlus_ImageGetGraphicsContext($bmpfront)
    Local $hPen = _GDIPlus_PenCreate(0, 1)
    Local $Wechsel = Round((9 / 20) * $h)
    Local $temp = _Gradient($startRGB, $endRGB, 3)
    $temp = _ZwischenGrad($temp[1], 0)
    Local $Gradient = _Gradient($startRGB, $temp, $Wechsel, 1)
    Local $Gradient2 = _Gradient($temp, $endRGB, $h - $Wechsel, 1)
    Local $PenColor
    For $i = 0 To $h - 1
        If $i < $Wechsel Then
            $PenColor = $Gradient[$i]
        Else
            $PenColor = $Gradient2[$i - $Wechsel]
        EndIf
        _GDIPlus_PenSetColor($hPen, $PenColor)
        _GDIPlus_GraphicsDrawLine($graph_front, 0, $i, $w, $i, $hPen)
    Next
    _GDIPlus_PenSetColor($hPen, 0xFF666666)
    _GDIPlus_GraphicsDrawRect($graph_front, 0, 0, $w, $h, $hPen)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($graph_front)
EndFunc   ;==>_CreateGradientImg

#EndRegion Gradient
;-------------------------------------------------------------------

;-------------------------------------------------------------------
#Region Internal
; Internal Function, do not use !
Func _Paint_Bars_Procedure($hWnd, $nMsg, $wParam, $lParam)
    For $i = 1 To UBound($_Progress_Bars) - 1
        If Not ($_Progress_Bars[$i][0] = -1) Then _ProgressRefresh($i);
    Next
EndFunc   ;==>_Paint_Bars_Procedure

; Internal Function, do not use !
; Author(s):       Prog@ndy
Func _Progress_CallBack_Init($ForceReInit = False)
    Local $sFuncName = "_Paint_Bars_Procedure", $iTime = 50, $sParam = "hwnd;int;int;dword"
    $_Progress_ahCallBack[2] += 1
    If $_Progress_ahCallBack[2] > 1 And Not $ForceReInit Then Return True
    If $ForceReInit Then
        Local $temp = $_Progress_ahCallBack[2]
        _Progress_CallBack_Free(1)
        $_Progress_ahCallBack[2] = $temp
    EndIf
    Local $hCallBack = DllCallbackRegister("_Paint_Bars_Procedure", "int", $sParam)

    Local $aTimer = DllCall("user32.dll", "uint", "SetTimer", _
            "hwnd", 0, "uint", 0, "int", $iTime, "ptr", DllCallbackGetPtr($hCallBack))

    $_Progress_ahCallBack[0] = $hCallBack
    $_Progress_ahCallBack[1] = $aTimer[0]

    Return True
EndFunc   ;==>_Progress_CallBack_Init

; Internal Function, do not use !
; Author(s):       Prog@ndy
Func _Progress_CallBack_Free($Force = False)
    $_Progress_ahCallBack[2] -= 1
    If $_Progress_ahCallBack[2] < 0 Then
        $_Progress_ahCallBack[2] = 0
        Return
    EndIf
    If (Not $Force) And ($_Progress_ahCallBack[2] > 0) Then Return
    ConsoleWrite("!DEBUG Variables ------------------" & @CRLF)
    ConsoleWrite("! $Force" & $Force & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[2]" & $_Progress_ahCallBack[2] & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[0]" & $_Progress_ahCallBack[1] & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[1]" & $_Progress_ahCallBack[1] & @CRLF)
    ConsoleWrite("!----------------------------------" & @CRLF)
    If $_Progress_ahCallBack[1] <> -1 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", 0*ConsoleWrite("KILL" & @CRLF) , "uint", $_Progress_ahCallBack[1])
    ConsoleWrite("!DEBUG after Kill TImer" & @CRLF)
    ConsoleWrite("!DEBUG Variables ------------------" & @CRLF)
    ConsoleWrite("! $Force" & $Force & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[2]" & $_Progress_ahCallBack[2] & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[0]" & $_Progress_ahCallBack[1] & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[1]" & $_Progress_ahCallBack[1] & @CRLF)
    ConsoleWrite("!----------------------------------" & @CRLF)
    If $_Progress_ahCallBack[0] <> -1 Then DllCallbackFree($_Progress_ahCallBack[0])
    ConsoleWrite("!DEBUG after Free callback" & @CRLF)
    ConsoleWrite("!DEBUG Variables ------------------" & @CRLF)
    ConsoleWrite("! $Force" & $Force & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[2]" & $_Progress_ahCallBack[2] & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[0]" & $_Progress_ahCallBack[1] & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[1]" & $_Progress_ahCallBack[1] & @CRLF)
    ConsoleWrite("!----------------------------------" & @CRLF)
    $_Progress_ahCallBack[0] = -1
    $_Progress_ahCallBack[1] = -1
    $_Progress_ahCallBack[2] = 0
    ConsoleWrite("!DEBUG after Var REset" & @CRLF)
    ConsoleWrite("!DEBUG Variables ------------------" & @CRLF)
    ConsoleWrite("! $Force" & $Force & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[2]" & $_Progress_ahCallBack[2] & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[0]" & $_Progress_ahCallBack[1] & @CRLF)
    ConsoleWrite("! $_Progress_ahCallBack[1]" & $_Progress_ahCallBack[1] & @CRLF)
    ConsoleWrite("!----------------------------------" & @CRLF)
EndFunc   ;==>_Progress_CallBack_Free


;~ Func _DebugPrint($s_text)
;~  $s_text = StringReplace($s_text, @LF, @LF & "-")
;~  ConsoleWrite($s_text & @LF); & _
;~ EndFunc   ;==>_DebugPrint

Func __CheckForGDIPlus($Fatal = True)
    Local $x = DllOpen("GDIPlus.dll")
    Local $ret = DllCall("Kernel32.dll", "dword", "GetModuleHandle", "str", "GDIPlus")
    DllClose($x)
    If $ret[0] = 0 And $Fatal Then _WinAPI_FatalAppExit("GDIplus not found. Please install GDIplus to use this application")
    Return ($ret[0] = 0)
EndFunc   ;==>__CheckForGDIPlus

#EndRegion Internal
;-------------------------------------------------------------------

Func _InverseColor($Col)
    $Col = Number($Col)
    Local $a = BitAND($Col,0xFF)
    Local $b = BitAND(BitShift($Col,8),0xFF)
    Local $c = BitAND(BitShift($Col,16),0xFF)
    Return BitOR(BitShift(255-$c,-16), BitShift(255-$b,-8), 255-$a)
EndFunc

 

GDIpProgress.au3

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • By ozymandius257
      This is probably a very simple question (I hope!)
      I'm looking to use a UDF to access a SQL database, and have found ADO.au3, but I can't seem to work out how to use it.
      I've copied the files ado.au3 and ado_constants.au3 into the folder C:\Program Files (x86)\AutoIt3\Include, then opened SciTe and started a new project.
      But when I type #include<AD - I don't get offered ADO.au3.
      (I know I should be using the folder C:\Program Files (x86)\AutoIt3\UserInclude, but when it didn't work from there, I tried the above).
      What am I doing wrong?
       
    • By BetaLeaf
      What is Rollbar?
      Rollbar provides real-time error alerting & debugging tools for developers. Learn more about it at https://rollbar.com/product/
      Demo: https://rollbar.com/demo/demo/
      Screenshot:
      Instructions: (RollbarTest.au3)
      ; Include RollbarSDK #include "RollbarSDK.au3" ;Turns on ConsoleWrite debugging override. ;Global $Rollbar_Debug=False ; Initialize RollbarSDK with the project's API key. ; Parameters ....: $__Rollbar_sToken - [Required] Go to https://rollbar.com/<User>/<ProjectName>/settings/access_tokens/ for your project. Use the token for post_server_item. _Rollbar_Init("eaa8464a4082eeabd9454465b8f0c0af") ; Write code that causes an error you want to catch, then call ; _Rollbar_Send ; Parameters ....: $__Rollbar_sErrorLevel - [Required] Must be one of the following values: Debug, Info, Warning, Error, Critical. ; $__Rollbar_sMessage - [Required] The message to be sent. This should contain any useful debugging info that will help you debug. ; $__Rollbar_sMessageSummary - [Optional] A string that will be used as the title of the Item occurrences will be grouped into. Max length 255 characters. If omitted, Rollbar will determine this on the backend. _Rollbar_Send("Debug", "This is an debug message. If you received this, you were successful!", "Debug Message") _Rollbar_Send("Info", "This is a test message. If you received this, you were successful!", "Info Message") _Rollbar_Send("Warning", "This is an warning message. If you received this, you were successful!", "Warning Message") _Rollbar_Send("Error", "This is an error message. If you received this, you were successful!", "Error Message") _Rollbar_Send("Critical", "This is an critical message. If you received this, you were successful!", "Critical Message") _Rollbar_Send("Info", "This is a test message. If you received this, you were successful!") ;No Message ; Rollbar_Send's helper functions ; Parameters ....: $__Rollbar_sMessage - [Required] The message to be sent. This should contain any useful debugging info that will help you debug. ; $__Rollbar_sMessageSummary - [Optional] A string that will be used as the title of the Item occurrences will be grouped into. Max length 255 characters. If omitted, Rollbar will determine this on the backend. _Rollbar_SendDebug("This is an debug message. If you received this, you were successful!", "Debug Message") _Rollbar_SendInfo("This is a test message. If you received this, you were successful!", "Info Message") _Rollbar_SendWarning("This is an warning message. If you received this, you were successful!", "Warning Message") _Rollbar_SendError("This is an error message. If you received this, you were successful!", "Error Message") _Rollbar_SendCritical("This is an critical message. If you received this, you were successful!", "Critical Message") ; Usable Example Local $sImportantFile = "C:\NOTAREALFILE_1234554321.txt" Switch FileExists($sImportantFile) Case True MsgBox(0, "Example Script", "An important file was found. Continuing...") Case Else _Rollbar_SendCritical('An important file was missing. Halting... File: "' & $sImportantFile & '"', 'Important file "' & $sImportantFile & '" is missing.') EndSwitch Notes: Please comment your feedback, advice, & suggestions below. While this is only a proof of concept, I will expand its feature set for everyone to use. 
      Right now, it is fully functional but not tested in production.
       
       
      Changelog:
      RollbarSDK.au3
      RollbarTest.au3
      v0.2
       
      v0.1.1
       
    • By kurtykurtyboy
      GuiFlatButton is a UDF to easily create regular buttons with different colors for background, foreground, border, hover, focus, etc..
      This started as an effort to change the background color of a button and eventually grew into a full UDF.
      If you've looked around forums for changing button background colors, you have probably noticed that each proposed workaround has its own set of issues/side-effects. The answers usually circle back to 'use ownerdrawn buttons' and 'not worth it'. Well, now it is possible for anyone to easily create ownerdrawn buttons - totally worth it!
      Some issues with other workarounds such as drawing with GDI+ or using a colored label as a 'button':
      Not 'real' buttons so you lose built-in functionality that windows gives to buttons Messy / inefficient code in the main while loop to check for mouse position Slow to respond to click, paint, etc... Having to deal with GUIRegisterMsg messages Not straight-forward to implement GuiFlatButton is not a workaround; it is a technique to respond to Windows' built-in owner-drawn button events.
      With minimal effort, we can now create true simple colored buttons.
      The idea is to create an owner-drawn button using GUICtrlCreateButton then subclass the GUI and controls to handle the button-specific events to paint it however we want.
      This UDF magically does all of this for us! No need to worry about event handling or main while loop logic.
       
      How to use
      It couldn't be any easier! Simply create a new button using the familiar syntax. This creates an ownerdrawn button with default colors.
      $mybutton1 = GuiFlatButton_Create("Button 1", 78, 20, 120, 40) If you want to change the background and text colors:
      GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) Advanced Usage
      Set background/text/border all at once
      GuiFlatButton_SetColors(-1, 0x0000FF, 0xFFFFFF, 0x9999FF) Set ALL colors for ALL button states! (normal, focus, hover, selected)
      Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetColorsEx(-1, $aColorsEx) Set default colors to apply to any future buttons
      ;set colors GuiFlatButton_SetDefaultColors(0x0000FF, 0xFFFFFF, 0x9999FF) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40) Set ALL color defaults
      ;set colors Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40)  
      Available Functions
       
      Simple Example

      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;GUI with one button Func Example() Local $hGUI, $mybutton1 $hGUI = GUICreate("GuiFlatButton Ex0", 275, 120) GUISetBkColor(0x333333) $idLabel = GUICtrlCreateLabel("Click the button", 10, 100, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) ;create new button then set the background and foreground colors $mybutton1 = GuiFlatButton_Create("Button 1", 78, 20, 120, 40) GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $mybutton1 $i += 1 GUICtrlSetData($idLabel, $i) ConsoleWrite($i & @CRLF) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example
      Menu/Toolbar Example

      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;Example GUI with toolbar Func Example() Local $hGUI, $idLabel, $aButtons, $iTbSize $hGUI = GUICreate("GuiFlatButton Ex2", 300, 200) GUISetBkColor(0x444444) $idLabel = GUICtrlCreateLabel("Click a button", 10, 180, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) $aButtons = createToolbar() $iTbSize = UBound($aButtons) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $aButtons[0] To $aButtons[$iTbSize - 1] ConsoleWrite("1") GUICtrlSetData($idLabel, GuiFlatButton_Read($iMsg)) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example Func createToolbar() Local $aButtons[6] Local $bkColor = 0x777777 Local $textColor = 0xFFFFFF Local $borderColor = 0x999999 Local $aBtnClrs[12] = [0x777777, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x888888, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x999999, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x666666, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT] For $i = 0 To UBound($aButtons) - 1 $aButtons[$i] = GuiFlatButton_Create("B" & $i, $i * 50, 0, 50, 17) GuiFlatButton_SetColorsEx($aButtons[$i], $aBtnClrs) Next Return $aButtons EndFunc ;==>createToolbar  
      Icon Example
      You can even easily add icons to your buttons -- just create a new button and send it an icon!

      #include <GDIPlus.au3> #include "GuiFlatButton.au3" Example() ;buttons with Icon images Func Example() ;get images for demonstration _GDIPlus_Startup() ;initialize GDI+ Local $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 258, 24, 24) ;extract the 'Save' icon Local $hBitmap = _GDIPlus_BitmapCreateFromHICON($hIcon) ;Create Bitmap from Icon (for demonstration) Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;Create HBitmap from Bitmap _GDIPlus_BitmapDispose($hBitmap) ;dispose the bitmap _GDIPlus_Shutdown() ;done with GDI+ Local $hGUI = GUICreate("GuiFlatButton Ex5", 255, 400) GUISetBkColor(0xEEEEEE) ;set default colors of future buttons Local $aColorsEx = _ [0xE2E5E8, 0X000000, 0x888888, _ ; normal : Background, Text, Border 0xE2E5E8, 0X000000, 0x333333, _ ; focus : Background, Text, Border 0xE8E8E8, 0X000000, 0x666666, _ ; hover : Background, Text, Border 0xDDDDDD, 0X000000, 0xAAAAAA] ; selected : Background, Text, Border GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;normal button with icon $label1 = GUICtrlCreateLabel( "$BS_TOOLBUTTON -->", 5, 10) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Local $mybutton1 = GuiFlatButton_Create("Save", 130, 5, 50, 48, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybutton1), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top Local $mybuttonT = GuiFlatButton_Create("Top", 5, 65, 120, 55, $BS_TOP) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonT), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-left Local $mybuttonTL = GuiFlatButton_Create("Top-Left", 5, 125, 120, 55, BITOR($BS_TOP, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-right Local $mybuttonTR = GuiFlatButton_Create("Top-Right", 5, 185, 120, 55, BITOR($BS_TOP, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align left Local $mybuttonL = GuiFlatButton_Create("Left", 5, 245, 120, 55, $BS_LEFT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom Local $mybuttonB = GuiFlatButton_Create("Bottom", 130, 65, 120, 55, $BS_BOTTOM) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonB), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-left Local $mybuttonBL = GuiFlatButton_Create("Bottom-Left", 130, 125, 120, 55, BITOR($BS_BOTTOM, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-right Local $mybuttonBR = GuiFlatButton_Create("Bottom-Right", 130, 185, 120, 55, BITOR($BS_BOTTOM, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align right Local $mybuttonR = GuiFlatButton_Create("Right", 130, 245, 120, 55, $BS_RIGHT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) GuiFlatButton_SetState($mybuttonR, $GUI_DISABLE ) ;disabled Local $mybuttonDisable = GuiFlatButton_Create("Disabled", 130, 310, 120, 55, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonDisable), $BM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) GuiFlatButton_SetState($mybuttonDisable, $GUI_DISABLE ) ;clean up! _WinAPI_DestroyIcon( $hIcon ) _WinAPI_DeleteObject( $hHBitmap ) GUISetState(@SW_SHOW, $hGUI) Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example  
      I'm sure there are some use-cases I've forgotten, so feedback is welcome!
       
      Download the UDF and several more examples: GuiFlatButton_20190414.zip
      Update 2019-04-14
      Fixed bug, not showing pressed down state when clicking rapidly
      Added Icon/Bitmap support!
      Added function GuiFlatButton_SetPos to change the position and/or size of a button
      Update 2019-02-09
      Added 2 new functions to set the button colors globally for all future buttons.
      GuiFlatButton_SetDefaultColors 
      GuiFlatButton_SetDefaultColorsEx

      Credits to:
      Melba23 (UDF template)
      LarsJ (general subclassing code)
      4ggr35510n (TrackMouseEvent example)
      binhnx (disable dragging with $WS_EX_CONTROLPARENT)
      GUIRegisterMsg in AutoIt Help (owner-draw button example)
      funkey (_WinAPI_DrawState example)
    • By MFrancisca
      Hello! 
      I've been checking the logging UDFs in the wiki, mostly Log4a and Loga and I wanted to ask which one would you recommend for a script that will be executed remotely through PSExec. My main question is where the logs are located in that situation and if I can change that location to a custom one., because I need to retrieve them at the end of execution.
      So in a rough description the process is
      Open PSExec
      Send compiled AutoIT script to remote machine
      Execute script
      Copy logs from the remote to the local machine.
       
      Any opinions? 
    • By caramen
      I watched _OL_ItemSend&_OL_ItemFind&_OL_ItemCreate in OutlookEx UDF but hmmm
       
      Since it use the test environnement i cant get the orders of the mail creation
       
      Can someone make me win some time of reading all exemples script and lead me how to do one ?
      That whould be lovely.
      Gnight
×
×
  • Create New...