Progress Bar mit Bitmaps

  • Hi,

    ich habe ein schönes snippet im engl. Forum gefunden und mir eine kleine Funktion draus gebastelt ...
    http://www.autoitscript.com/forum/index.php?showtopic=64703&view=findpost&p=483526

    Update 18.o5.o8

    Beispiel

    Spoiler anzeigen
    [autoit]

    #NoTrayIcon
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_outfile=progressEx2.exe
    #AutoIt3Wrapper_UseUpx=n
    #AutoIt3Wrapper_Res_Language=1031
    #AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 1.bmp, bitmap, 1, 1031
    #AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 2.bmp, bitmap, 2, 1031
    #AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 3.bmp, bitmap, 3, 1031
    #AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 4.bmp, bitmap, 4, 1031
    #AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 5.bmp, bitmap, 5, 1031
    #AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\SciTE\AutoIt3Wrapper\ResHacker.exe -add %out%, %out%, 6.bmp, bitmap, 6, 1031
    #AutoIt3Wrapper_Run_After=C:\Programme\AutoIt3\Aut2Exe\upx.exe --best --compress-resources=1 "%out%"
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include-once
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    #include <ProgressBar.au3>

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

    Global Const $SS_CENTER = 1

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

    ; Wichtig ! s. Funktion.
    Opt('OnExitFunc', 'Terminate')

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

    ; Array mit Bitmaps von der Festplatte !!!
    Global $aPics[6] = ['1.bmp', '2.bmp', '3.bmp', '4.bmp', '5.bmp', '6.bmp']

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

    ; Array mit Bitmaps aus den Resourcen !!!
    ;Global $aPics[6] = [1, 2, 3, 4, 5, 6]

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

    ; Testfenster erstellen.
    $hWnd = GUICreate('ProgressBar mit Bitmaps - Demo', 500, 300, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
    GUISetBkColor(0xFFFFFF)
    GUISetFont(10, 800, 0, 'SegoeUI')

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

    GUICtrlCreateLabel('Progressbar Test', 0, 80, 500, 20, $SS_CENTER)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 12, 800, 0, 'SegoeUI')

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

    $aProgressBar1 = ProgressBarCreate(100, 150, 300, $aPics, $hWnd)
    ProgressBarSetState($aProgressBar1)

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

    GUISetState(@SW_SHOW, $hWnd)

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

    $aProgressBar2 = ProgressBarCreate(100, 150, 500, $aPics)
    ProgressBarSetState($aProgressBar2)

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

    Sleep(1500)
    TestProgress($aProgressBar1)
    TestProgress($aProgressBar2)

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

    ; muss vor Programmende aufgerufen werden,
    ; um mit den Resourcen aufzuräumen.
    ;ProgressBarDelete($aProgressBar1)
    ;ProgressBarDelete($aProgressBar2)

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

    While True

    Switch GUIGetMsg()
    Case -3
    Exit
    EndSwitch

    WEnd

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

    Func TestProgress($aProgress)

    For $i = 1 To 100
    ProgressBarSetData($aProgress, $i)
    Sleep(1)
    Next

    EndFunc

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

    Func Terminate()

    ; muss vor Programmende aufgerufen werden,
    ; um mit den Resourcen aufzuräumen.
    ProgressBarDelete($aProgressBar1)
    ProgressBarDelete($aProgressBar2)

    EndFunc

    [/autoit]


    ProgressBar.au3

    Spoiler anzeigen
    [autoit][/autoit] [autoit][/autoit] [autoit]

    #include-once
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

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

    Func ProgressBarCreate($x, $y, $iWidth, $aBitmaps, $hWndParent = 0)

    Local $dwStyleCtrl, $dwExStyleCtrl, $aProgress[3][$iWidth + 1]
    $aProgress[1][0] = $iWidth
    $aProgress[0][3] = 1

    If Not IsArray($aBitmaps) Then
    Return SetError(1, 1, 0)
    EndIf

    Local $i, $eBmp, $fuLoad, $hInst, $hInstance = GetModuleHandle()

    For $eBmp In $aBitmaps

    $i += 1
    If IsString($eBmp) Then
    $hInst = Ptr(0)
    $fuLoad = 16
    ElseIf IsInt($eBmp) Then
    $hInst = $hInstance
    $fuLoad = 0
    EndIf

    $aProgress[2][$i] = LoadImage($hInst, $eBmp, 0, 0, 0, $fuLoad)

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

    Next


    If Not $hWndParent Or $hWndParent = 0 Then
    $aProgress[0][0] = GUICreate('ProgressBar', $iWidth, 15, $x, $y, _
    BitOR($WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_POPUP), _
    BitOR(0x2000000, $WS_EX_LAYERED))
    $dwStyleCtrl = BitOR(0x0100, $WS_CHILD)
    $dwExStyleCtrl = BitOr($WS_EX_LAYERED,$GUI_WS_EX_PARENTDRAG, $WS_EX_TOPMOST)
    $x = 0
    $y = 0
    Else
    $dwStyleCtrl = $WS_CHILD
    $dwExStyleCtrl = $WS_EX_TOPMOST
    EndIf

    $aProgress[1][1] = GUICtrlCreatePic('', $x, $y, 2, 15, BitOR($dwStyleCtrl, $WS_GROUP), $dwExStyleCtrl)
    GUICtrlSetState(-1, $GUI_ONTOP)
    GUICtrlSendMsg($aProgress[1][1], 0x0172, 0, $aProgress[2][1])

    For $i = 2 To $iWidth - 3
    $aProgress[1][$i] = GUICtrlCreatePic('', $x + $i, $y, 1, 15, $dwStyleCtrl, $dwExStyleCtrl)
    GUICtrlSetState(-1, $GUI_ONTOP)
    GUICtrlSendMsg($aProgress[1][$i], 0x0172, 0, $aProgress[2][3])
    Next

    $aProgress[1][$iWidth] = GUICtrlCreatePic('', $x + $iWidth - 2, $y, 2, 15, BitOR($dwStyleCtrl, $WS_GROUP), $dwExStyleCtrl)
    GUICtrlSetState(-1, $GUI_ONTOP)
    GUICtrlSendMsg($aProgress[1][$iWidth], 0x0172, 0, $aProgress[2][2])

    $aProgress[0][1] = GUICtrlCreateLabel('0 %', $x + ($iWidth / 2) -15, $y, 40, 15, _
    BitOR($WS_VISIBLE, $WS_CLIPSIBLINGS, 1 , $dwStyleCtrl), $dwExStyleCtrl)
    GUICtrlSetFont(-1, 8.5, 800, 0, 'Segoe UI Fett')
    GUICtrlSetColor(-1,0x424242)

    If Not $hWndParent Then $aProgress[0][2] = GUICtrlSetTip(-1, "Drag me, please ... ;) ")

    Return $aProgress

    EndFunc

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

    Func ProgressBarSetData(ByRef $aProgress, $iPercent)

    If $iPercent <= 0 Then Return 0
    $cxStart = $aProgress[0][3]
    $cxEnd = Int(($aProgress[1][0] / 100) * $iPercent)
    $aProgress[0][3] = $cxEnd + 1

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

    For $i = $cxStart To $cxEnd
    If $i = 1 Then
    GUICtrlSendMsg($aProgress[1][1], 0x0172, 0, $aProgress[2][5])
    ElseIf $iPercent = 100 And $i = Int($cxEnd) Then
    GUICtrlSendMsg($aProgress[1][$aProgress[1][0]], 0x0172, 0, $aProgress[2][6])
    Else
    GUICtrlSendMsg($aProgress[1][$i], 0x0172, 0, $aProgress[2][4])
    EndIf
    Sleep(0)
    Next

    ProgressBarSetText($aProgress, $iPercent & ' %')

    EndFunc

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

    Func ProgressBarSetState($aProgress, $State = @SW_SHOW)

    GUISetState($State, $aProgress[0][0])

    GUICtrlSetBkColor($aProgress[0][1], $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetData($aProgress[0][1], '0 %')
    GUICtrlSetState($aProgress[0][1], $GUI_ONTOP)

    EndFunc

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

    Func ProgressBarSetText($aProgress, $sText)

    GUICtrlSetState($aProgress[0][1], $GUI_HIDE)
    GUICtrlSetData($aProgress[0][1], $sText)
    GUICtrlSetState($aProgress[0][1], $GUI_SHOW)

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

    EndFunc

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

    Func ProgressBarDelete($aProgress)

    If $aProgress[0][0] Then
    GUIDelete($aProgress[0][0])
    Else
    For $i = 1 To $aProgress[1][0]
    GUICtrlSendMsg($aProgress[1][$i], $WM_CLOSE, 0, 0)
    Next
    EndIf

    For $i = 1 To 6

    DeleteObject($aProgress[2][$i])

    Next

    EndFunc

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

    Func LoadImage($hInstance, $lpszName, $uType, $cxDesired = 0, $cyDesired = 0, $fuLoad = 0)

    If IsNumber($lpszName) Then $lpszName = MAKEINTRESOURCE($lpszName)
    Local $aResult = DllCall('user32.dll', 'hwnd', 'LoadImage', _
    'ptr', $hInstance, _
    'str', $lpszName, _
    'uint', $uType, _
    'int', $cxDesired, _
    'int', $cyDesired, _
    'uint', $fuLoad)
    Return $aResult[0]

    EndFunc

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

    Func GetModuleHandle($sModule = '')

    Local $aResult = DllCall('kernel32.dll', 'hwnd', 'GetModuleHandle', 'ptr', StringLeft($sModule, 4095) & Chr(0))

    Return $aResult[0]

    EndFunc

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

    Func DeleteObject($hObject)

    Local $aResult = DllCall('gdi32.dll', 'int', 'DeleteObject', 'hwnd', $hObject)
    Return $aResult[0]

    EndFunc

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

    Func MAKEINTRESOURCE($lID)

    Return "#" & String(Int($lID))

    EndFunc

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


    autoit.de/wcf/attachment/2237/autoit.de/wcf/attachment/2238/

    Gruß
    Greenhorn

  • geil,
    echt super :D

    Sieht supi aus :thumbup:

    Genial wäre es, wenn du es in eine UDF packen könntest :)