Progressbar mit GDIplus

  • Ich habe eine UDF für Progressbars mit GDIplus geschrieben:
    Die Basis war How about a progressbar like this? aus dem englischen Forum.

    Spoiler anzeigen
    [autoit]

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

    AutoIt Version: 3.2.12.0
    Author: Prog@ndy
    after Script from nobbe ( 2008 in http://www.autoitscript.com/forum/index.ph…ndpost&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 ----------------------------------------------------------------------------
    ;===============================================================================
    ;
    ; 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
    ;
    ;===============================================================================
    ;
    ;===============================================================================
    ;
    ; 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
    ;
    ;===============================================================================
    ;
    ;===============================================================================
    ;
    ; 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
    ;
    ;===============================================================================
    ;
    ;===============================================================================
    ;
    ; 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
    ;
    ;===============================================================================
    ;
    ;===============================================================================
    ;
    ; 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
    ;
    ;===============================================================================
    ;
    ;===============================================================================
    ;
    ; 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
    ;
    ;===============================================================================
    ;
    ;===============================================================================
    ;
    ; 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)
    ; $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
    ;
    ;===============================================================================
    ;
    ;===============================================================================
    ;
    ; 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
    ;
    ;===============================================================================
    ;
    ;===============================================================================
    ;
    ; 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
    ;
    ;===============================================================================
    ;

    [/autoit]
    Spoiler anzeigen
    [autoit]

    #include <GDIpProgress.au3>
    ;##################################
    ; EXAMPLE
    #Region EXAMPLE

    [/autoit] [autoit][/autoit] [autoit]

    $Gui = GUICreate("Gradient ProgressBar", 400, 350)

    [/autoit] [autoit][/autoit] [autoit]

    ;Progress 1 + Controls
    $slid = GUICtrlCreateSlider(5, 20, 310, 30) ;; check only for first bar
    $Status_Label = GUICtrlCreateLabel("0%", 330, 30, 30, 20)
    $btn_0 = GUICtrlCreateButton("0", 2, 100, 15, 25, 0)
    $btn_25 = GUICtrlCreateButton("25", 20, 100, 75, 25, 0)
    $btn_50 = GUICtrlCreateButton("50", 120, 100, 75, 25, 0)
    $btn_75 = GUICtrlCreateButton("75", 220, 100, 75, 25, 0)
    $btn_cl1 = GUICtrlCreateButton("Colors 1", 20, 140, 75, 25, 0)
    $btn_cl2 = GUICtrlCreateButton("Colors 2", 220, 140, 75, 25, 0)
    $btn_vistOK = GUICtrlCreateButton("Vista OK", 220, 180, 75, 25, 0)
    $btn_vistError = GUICtrlCreateButton("Vista Error", 220, 210, 75, 25, 0)
    $btn_vistPause = GUICtrlCreateButton("Vista Pause", 220, 240, 75, 25, 0)
    $btn_txt = GUICtrlCreateButton("Set Text", 100, 180, 75, 25, 0)
    $in_txt = GUICtrlCreateInput("%P%", 20, 180, 75, 25, 0)
    GUICtrlSetTip(-1, "Use %P% to show Percentage" & @CRLF & "Leave empty to show no text")
    $sID = _ProgressCreate(10, 60, 300, 40)
    _ProgressSetText($sID, "Install %P%%")

    [/autoit] [autoit][/autoit] [autoit]

    ; End Progress 1 + Controls

    [/autoit] [autoit][/autoit] [autoit]

    ;Progress 2 + Controls
    $Progress2 = _ProgressCreate(10, 280, 300, 20)
    _ProgressSet($Progress2, 43)
    $input = GUICtrlCreateInput("43", 320, 280, 50, 20, $ES_NUMBER)
    GUICtrlSetLimit($input, 3, 1)
    $updown = GUICtrlCreateUpdown($input)
    GUICtrlSetLimit($updown, 100, 0)
    ;End Progress 2 + Controls

    [/autoit] [autoit][/autoit] [autoit]

    ;Progress Marquee + Controls
    $PMarquee = _ProgressCreate(10, 310, 300, 30)
    _ProgressSetImages($PMarquee, @ScriptDir & "\prgimgs\marquee.jpg", @ScriptDir & "\prgimgs\bg.jpg")
    _ProgressMarquee($PMarquee, 2, 0)
    $marVist = GUICtrlCreateCheckbox("Vista Style",315,315,100,20)
    GUICtrlSetState(-1,$GUI_CHECKED)
    ;End Progress Marquee + Controls

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1

    [/autoit] [autoit][/autoit] [autoit]

    $nMsg = GUIGetMsg()
    Switch $nMsg

    [/autoit] [autoit][/autoit] [autoit]

    Case $btn_0
    _ProgressSet($sID, 0)
    GUICtrlSetData($slid, 0)
    Case $btn_25
    _ProgressSet($sID, 25)
    GUICtrlSetData($slid, 25)
    Case $btn_50
    _ProgressSet($sID, 50)
    GUICtrlSetData($slid, 50)
    Case $btn_75
    _ProgressSet($sID, 75)
    GUICtrlSetData($slid, 75)

    Case $btn_cl1
    _ProgressSetColors($sID, 0xFF0000, 0x00FF00, 0xA1B0BB, 0x4455FF)
    _ProgressSetFont($sID, "", -1, -1, 0xFFBBBBFF, True)
    Case $btn_cl2
    _ProgressSetColors($sID, 0x89A49B, 0xF0D6C7, 0xFFFFFF, 0xFFFFFF)
    _ProgressSetFont($sID, "", -1, -1, 0x000000)
    Case $btn_vistOK
    _ProgressSetImages($sID, @ScriptDir & "\prgimgs\green.jpg", @ScriptDir & "\prgimgs\bg.jpg")
    _ProgressSetFont($sID, "", -1, -1, 0x0000FF)
    Case $btn_vistPause
    _ProgressSetImages($sID, @ScriptDir & "\prgimgs\yellow.jpg", @ScriptDir & "\prgimgs\bg.jpg")
    _ProgressSetFont($sID, "", -1, -1, 0xFF0000)
    Case $btn_vistError
    _ProgressSetImages($sID, @ScriptDir & "\prgimgs\red.jpg", @ScriptDir & "\prgimgs\bg.jpg")
    _ProgressSetFont($sID, "", -1, -1, 0x000000)

    Case $btn_txt
    _ProgressSetText($sID, GUICtrlRead($in_txt))
    Case $input, $updown
    _ProgressSet($Progress2, GUICtrlRead($input))

    Case $marVist
    If BitAND(GUICtrlRead($marVist),$GUI_CHECKED) = $GUI_CHECKED Then
    _ProgressSetImages($PMarquee, @ScriptDir & "\prgimgs\marquee.jpg", @ScriptDir & "\prgimgs\bg.jpg")
    Else
    _ProgressSetColors($PMarquee, 0xFFFF00, 0x00FF00, 0xAAAA00, 0xFF0000)
    _ProgressMarquee($PMarquee, 2, 1)
    EndIf

    Case $GUI_EVENT_CLOSE
    _ProgressDelete($sID) ; MUST BE DONE ON EXIT
    _Progress_CallBack_Free(1) ; Force Killing Timer

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    Exit
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    If $iPercent <> GUICtrlRead($slid) Then
    $iPercent = GUICtrlRead($slid)
    GUICtrlSetData($Status_Label, $iPercent & "%")
    _ProgressSet($sID, $iPercent)
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    WEnd

    [/autoit]

    Changelog

    • 16.6.08

      • Beispiel abgetrennt
      • Marquee hinzugefügt
    • 20.7.08

      • Fehler in _ProgressDelete berichtigt


    //Edit: Bild:

    Spoiler anzeigen


    Vorige Downloads: 42
    Download ab jetzt hier: DOWNLOAD

    6 Mal editiert, zuletzt von progandy (5. Dezember 2009 um 15:03)

  • Hi,
    ich habe mir eben die neue Version im englischen Board heruntergeladen.
    Das bekomme ich allerdings beim beenden deines Bsps folgende Fehlermeldung:

    Zitat

    C:\Programme\AutoIt3\Include\GDIpProgress.au3 (106) : ==> Subscript used with non-Array variable.:
    Local $temp = GUICtrlDelete($temp[0])
    Local $temp = GUICtrlDelete($temp^ ERROR

  • Ich hab keine Fehlermeldung... Es kommt nur KILL, das soll aber auch so sein :)
    Habs extra runtergeladen und mit der Version getestet.

  • :rofl: oh man, ich hatte deine gepackte Datei nur entpackt und getestet.
    Aber er nimmt sich die udf ja aus dem include Verzeichnis und da war logischerweise noch die alte drin :rofl:

    nun gehts danke :D

  • WOW!
    Das ist echt eine tolle UDF!
    Ich hab sowas schonmal gesucht aber nichts gutes gefunden echt vielen Dank! :thumbup:

  • ist auf jeden fall ne nice sache, aber ...

    wenn ich einfach nur ne progressbar mit farbigen durchlauf (vista style) erstellen will, habe ich immer zusätzlich die 4 punkte die blinken.
    und die wegzubekommen habe ich _ProgressSetText(" ") genommen, dann erscheint aber ganz kurz "0 %" im gui.

    gleiches gilt für die farbliche darstellung beim vista style, ganz am anfang ist der balken rot. kann man das ändern?

    mein gui sieht zZ so aus:

    [autoit]

    #include <GDIpProgress.au3>

    [/autoit][autoit][/autoit][autoit]

    $ProgressGui = GUICreate("S.T.A.R.T.E.R", 200, 32, -1, -1, BitOR($WS_SIZEBOX, $WS_POPUP, $WS_VISIBLE, $DS_SETFOREGROUND), BitOR($WS_EX_STATICEDGE, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    WinSetTrans($ProgressGui, "", 200)
    GUISetBkColor(0x000000, $ProgressGui)
    $ProgressLabel = GUICtrlCreateLabel("S.T.A.R.T.E.R is working", 45, 3, 120, 18)
    GUICtrlSetColor($ProgressLabel, 0xFFFFFF);Progress Marquee + Controls
    $PMarquee = _ProgressCreate(1, 20, 197, 10)
    _ProgressSetImages($PMarquee, "C:\Program Files\AutoIt3\Include\prgimgs\marquee.jpg", "C:\Program Files\AutoIt3\Include\prgimgs\bg.jpg")
    _ProgressMarquee($PMarquee, 2, 0)
    _ProgressSetText($PMarquee, " ")
    GUISetState()

    [/autoit][autoit][/autoit][autoit]

    While 1
    Sleep(100)
    WEnd

    [/autoit]
  • Hallo, mir ist leider noch was aufgefallen.

    Die UDF läuft leider nicht, wenn man das Script Obfuscated. Wenn ich das richtig recherchiert habe, liegt dies in erster Linie an der "create"-funktion (bin mir nicht 100%tig sicher).
    vllt könnte das jmd mal ausprobieren und dies bestätigen, wiederlegen.

    sobald ich das script obfuscate kommt folgender fehler:

    ---------------------------
    AutoIt Error
    ---------------------------
    Line -1:


    Error: Badly formatted "Func" statement.
    ---------------------------
    OK
    ---------------------------

  • So, die Lösung sollte sein:
    1) Setze den text bevor du auf Marquee schaltest :)
    2) das liegt an einer fehlenden Zeile in \Programme\AutoIt3\SciTE\Obfuscator\Obfuscator.dat. Einfach mit notepad öffnen und folgendes hinzufügen:

    Code
    dllcallbackregister,1,0


    //Edit: Und einen Refresh einfügen :)

    Spoiler anzeigen
    [autoit]

    #include <GDIpProgress.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $ProgressGui = GUICreate("S.T.A.R.T.E.R", 200, 32, -1, -1, BitOR($WS_SIZEBOX, $WS_POPUP, $WS_VISIBLE, $DS_SETFOREGROUND), BitOR($WS_EX_STATICEDGE, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    WinSetTrans($ProgressGui, "", 200)
    GUISetBkColor(0x000000, $ProgressGui)
    $ProgressLabel = GUICtrlCreateLabel("S.T.A.R.T.E.R is working", 45, 3, 120, 18)
    GUICtrlSetColor($ProgressLabel, 0xFFFFFF);Progress Marquee + Controls
    $PMarquee = _ProgressCreate(1, 20, 197, 10,0x00FF00,0x00FF00,0x111111,0x111111)
    _ProgressSetText($PMarquee, "")
    _ProgressSetImages($PMarquee, "D:\Dokumente\Dateien von Andreas\AutoIt3\prgimgs\marquee.jpg", "D:\Dokumente\Dateien von Andreas\AutoIt3\prgimgs\bg.jpg")
    _ProgressRefresh($PMarquee)
    _ProgressMarquee($PMarquee, 2, 0)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(100)
    WEnd

    [/autoit]

    Einmal editiert, zuletzt von progandy (30. August 2008 um 22:58)

  • Tach auch

    Das schaut sehr interessant aus vielleicht kann ich das für meine Scripte zur Installation verwenden ich teste es mal.

    Gruß

  • Hallo,
    ich weiß das es sehr alt ist, aber egal.

    Mein Script bleibt offt mitten im laden hengen und dannach tut sich rein garnichts.
    Damit ich es dann wieder zukriege, muss ich das Script per Task Manager ausmachen.

    Könnte sich das vll jemand angucken (die UDF) und versuchen den Fehler zu finden ?

    ps: Es kommt keine Fehlermeldung.

  • Ich hab auch ein Problem mit der UDF. Erstellen und Setzen und so klappt super.
    Wenn ich das Script allerdings beende, stürtzt es ab.
    Wenn ich vorher noch _ProgressDelete benutze, kommt direkt beim klick auf das Kreutzchen
    die Meldung "Autoit Script v3 funtioniert nicht mehr bla bla bla".

    [autoit]


    $PlayerProgress = 50
    $LevelProgress = _ProgressCreate(10,100,220,30)
    _progressSet($LevelProgress,$PlayerProgress)
    _progressSetColors($LevelProgress,0xdddddd,0xaaaaaa,0x000000,0x222222)
    _ProgressSetText($LevelProgress,$PlayerProgress & "%")
    _ProgressSetFont($LevelProgress,"",Default,Default,0xffffff)

    [/autoit]
  • Irgendwas hat sich in 3.3.8.1 geändert.

    Bei dem folgenden Beispiel siehts so aus

    Spoiler anzeigen
    [autoit]

    #region ;************ Includes ************
    #include <GDIpProgress.au3>
    #endregion ;************ Includes ************
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $Gui = GUICreate("3.3.6.1", 250, 50)
    $sID = _ProgressCreate(10, 10)
    _ProgressSet($sID, 30)

    [/autoit] [autoit][/autoit] [autoit]

    GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    Sleep(10)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _beenden()
    _ProgressDelete($sID) ; MUST BE DONE ON EXIT
    _Progress_CallBack_Free(1) ; Force Killing Timer
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_beenden

    [/autoit]

    3.3.8.1autoit.de/wcf/attachment/15467/

    3.3.6.1autoit.de/wcf/attachment/15468/

    Kannst du mal danach schauen progandy?

  • Das ist ganz einfach meine schlechte Verlaufsfunktion, die mit den neuen Funktionen nicht korrekt funktioniert. Wenn die UDF so beliebt ist, muss ich doch mal drüber schauen :D
    Wenn ich mal dazukomme würde ich das genze gerne in ein Control verpacken mit weniger Zeichenoperationen (nicht alle 100ms alle Progressbars)