Jump to content

File Downloader with Pacman Progress Bar


Recommended Posts

So I recently asked UEZ for help adding his beautiful pacman progress bar to my file downloader program, and this is the awesome production he gave me.  What I wanted to do next might be a little difficult.  Right now there are two progress bars.  Individual Downloads and Overall Downloads.  The Overall downloads has a pacman progress bar (Thanks to UEZ) and I was wondering if someone could help add the top bar with the same thing, but everytime it hits a new file, change the color of the pacman (using the original colors or something from the game).

Thanks ahead of time!

#include <StaticConstants.au3>
#include <GUIConstants.au3>
#include <GUIStatusBar.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>

_GDIPlus_Startup()
; 2D array to hold URL and filesize
Dim $arrDownload[5][2]
; Put the number of elements into element [0][0]
$arrDownload[0][0] = UBound($arrDownload) - 1
; Setup the files to download
$arrDownload[1][0] = "http://www.malwarebytes.org/mbam/program/mbam-setup.exe"
$arrDownload[2][0] = "http://www.spybotupdates.com/files/spybotsd162.exe"
$arrDownload[3][0] = "http://cdn.superantispyware.com/SUPERAntiSpyware.exe"
$arrDownload[4][0] = "http://download.piriform.com/ccsetup403.exe"
; ## GUI ######
$Form = GUICreate("Downloader", 400, 220)
$butStart = GUICtrlCreateButton("Start", 75, 15, 100, 30)
$installAll = GUICtrlCreateButton("Install All", 225, 15, 100, 30)
$txtCurrent = GUICtrlCreateLabel("Current File Progress:", 30, 55, 100, 20)
$prgCurrent = GUICtrlCreateProgress(30, 75, 300, 10)
$lblCurrent = GUICtrlCreateLabel("0%", 340, 72, 30, 15, $SS_RIGHT)
$txtOverall = GUICtrlCreateLabel("Overall Progress:", 30, 105, 80, 20)
;~ $prgOverall = GUICtrlCreateProgress(30, 125, 300, 10)
$prgOverall = GUICtrlCreatePic("", 30, 125, 300, 30, $SS_SUNKEN)
$lblOverall = GUICtrlCreateLabel("0%", 340, 122, 30, 15, $SS_RIGHT)
$chkShutdown = GUICtrlCreateCheckbox("Shutdown PC when finished", 130, 170, 175, 20)
$StatusBar = _GUICtrlStatusBar_Create($Form)
_GUICtrlStatusBar_SetText($StatusBar, "Ready")
_GDIPlus_PacmanProgressbar(0, $prgOverall, $Form)
GUISetState(@SW_SHOW)
; ## END GUI #####

While 1

    $nMsg = GUIGetMsg()

    If $nMsg = $GUI_EVENT_CLOSE Then
        GUIDelete()
        _GDIPlus_Shutdown()
        Exit
    EndIf

    If $nMsg = $butStart Then doDownloads()

    If $nMsg = $installAll Then doInstalls()

WEnd

Func doInstalls()
    ShellExecuteWait(@DesktopDir & "\AllInOne.exe")

EndFunc   ;==>doInstalls


Func doDownloads()
    ; Variables for calculating percentages
    Local $CurrentFileSize = 0
    Local $TotalFileSize = 0
    Local $currBytesDownloaded = 0
    Local $overallBytesDownloaded = 0
    Local $TotalBytesDownloaded = 0
    Local $currPercent = 0
    Local $overallPercent = 0
    Local $Filename = ""
    Local $currDownload
    Local $CancelPressed = False
    ; Change the Start button to Cancel
    GuiCtrlSetData($butStart, "Cancel")

    ; Reset all progress data
    GUICtrlSetData($lblOverall, "0%")
;~     GUICtrlSetData($prgOverall, "0")
    _GDIPlus_PacmanProgressbar(0, $prgOverall, $Form)

    GUICtrlSetData($lblCurrent, "0%")
    GUICtrlSetData($prgCurrent, "0")


    ; Loop through all the URLs to get all the FileSizes (this allows us to calculate overall progress of ALL downloads)
    For $i = 1 To UBound($arrDownload) - 1

        ; Get the filename from after the last forward slash
        $Filename = StringRight($arrDownload[$i][0], StringLen($arrDownload[$i][0]) - StringInStr($arrDownload[$i][0], "/", -1, -1))

        _GUICtrlStatusBar_SetText($StatusBar, 'Getting filesize for file "' & $Filename & '"...')

        ; Put the filesize into second column of array
        $CurrentFileSize = INetGetSize($arrDownload[$i][0])

        ; We're going to use this filesize twice so put it in a variable so we only actually look it up once
        $arrDownload[$i][1] = $CurrentFileSize
        ; Add this to the total file size
        $TotalFileSize += INetGetSize($arrDownload[$i][0])

    Next


    ; Now do the individual downloads
    For $i = 1 To UBound($arrDownload) - 1

        ; Reset current bytes
        $currBytesDownloaded = 0

        ; Reset the current progress bar
        GUICtrlSetData($lblCurrent, "0%")
        GUICtrlSetData($prgCurrent, "0")

        ; Get the filename from after the last forward slash
        $Filename = StringRight($arrDownload[$i][0], StringLen($arrDownload[$i][0]) - StringInStr($arrDownload[$i][0], "/", -1, -1))

        _GUICtrlStatusBar_SetText($StatusBar, 'Downloading "' & $Filename & '" (' & $i & '/' & UBound($arrDownload) - 1 & ')...')

        ; Start the download
        $currDownload = INetGet($arrDownload[$i][0], @ScriptDir & "\" & $Filename, 1, 1)

        Do
            ; Check for messages
            Local $dMsg = GUIGetMsg()

            ; If the press the 'Cancel button
            If $dMsg = $butStart Then

                ; Check they really want to cancel
                Local $Confirm_Cancel = MsgBox(4, "Downloader", "Do You Want To Cancel All Downloads?", 0, $Form)

                ; If they do want to cancel
                If $Confirm_Cancel = 6 Then

                    ; stop the download
                    INetClose($currDownload)

                    ; notify the outer loop to exit
                    $CancelPressed = True
                    ExitLoop
                EndIf

            EndIf

            ; Get Current Bytes downloaded
            $currBytesDownloaded = INetGetInfo($currDownload, 0)

            ; Add current bytes downloaded to the total filesize of completed downloads
            $overallBytesDownloaded = $TotalBytesDownloaded + $currBytesDownloaded

            ; Get the current percentages
            $currPercent = ($currBytesDownloaded / $arrDownload[$i][1]) * 100
            $overallPercent = ($overallBytesDownloaded / $TotalFileSize) * 100

            ; Update the current progress bar
            GUICtrlSetData($prgCurrent, $currPercent)
;~             GUICtrlSetData($prgOverall, $overallPercent)
            _GDIPlus_PacmanProgressbar($overallPercent, $prgOverall, $Form)

            ; Update the progress labels only if they have changed (to avoid flicker)
            If GUICtrlRead($lblCurrent) <> floor($currPercent) & "%" Then GUICtrlSetData($lblCurrent, Floor($currPercent) & "%")
            If GUICtrlRead($lblOverall) <> floor($overallPercent) & "%" Then
                GUICtrlSetData($lblOverall, floor($overallPercent) & "%")
                WinSetTitle($Form, "", floor($overallPercent) & "% - Downloader")
            EndIf

        Until INetGetInfo($currDownload, 2)

        If Not $CancelPressed Then
            ; Set current progress to 100% here (sometimes gets stuck at 99 with rounding)
            GUICtrlSetData($prgCurrent, 100)
            GUICtrlSetData($lblCurrent, "100%")
        EndIf
        ; Add the filesize of this completed download to the total bytes downloaded
        $TotalBytesDownloaded += $arrDownload[$i][1]

        ; User cancelled - don't download anything else
        If $CancelPressed Then ExitLoop

    Next

    ; Reset the GUI labels
    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
    GUICtrlSetData($butStart, "Start")
    If $CancelPressed Then
        ; User cancelled
        MsgBox(48, "Downloader", "All downloads cancelled", 0, $Form)
    Else
        ; everything finished downloading

        ; Set current progress to 100% here (sometimes gets stuck at 99 with rounding)
        GUICtrlSetData($prgCurrent, 100)
        GUICtrlSetData($lblCurrent, "100%")


        ; Check if user wants us to shutdown
        If GUICtrlRead($chkShutdown) = $GUI_CHECKED Then
            ; Shutdown the PC if box is ticked and exit program
            Shutdown(29)
            Exit
        Else
            MsgBox(64, "Downloader", "All downloads complete", 0, $Form)
        EndIf

    EndIf
    ; Reset the window title
    WinSetTitle($Form, "", "Downloader")
EndFunc   ;==>doDownloads

Func _GDIPlus_PacmanProgressbar($iProgress, $iCtrl, $hGUI, $iProgressMax = 100, $iPackmanSpeed = 0.5, $iDotSize = 10, $iBGColor = 0xFF404040) ; coded by UEZ build 2013-07-26 beta
    Local $aResult, $hBitmap, $hGfxCtxt, $aCtrlSize, $hB, $hGDIBmp, $hBrush, $i, $iScalar = 10, $j = $iScalar - 1, $iSpace
    Local Static $iFrame = 0, $iTimer = TimerInit()
    $aCtrlSize = ControlGetPos($hGUI, "", $iCtrl)
    If @error Then Return SetError(1, 0, -1)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $aCtrlSize[2] - 2, "int", $aCtrlSize[3] - 2, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0)
    $hBitmap = $aResult[6]
    $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hGfxCtxt, $iBGColor)
    _GDIPlus_GraphicsSetSmoothingMode($hGfxCtxt, 2)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $iSpace = $aCtrlSize[2] / $iScalar
    If $iProgress < $iProgressMax Then
        For $i = ($iProgress / $iScalar) To $iScalar
            If $j = $iScalar - 1 Then
                _GDIPlus_BrushSetSolidColor($hBrush, 0xFFFF0000)
                _GDIPlus_GraphicsFillEllipse($hGfxCtxt, $iDotSize + $j * $iSpace, ($aCtrlSize[3] - (1.5 * $iDotSize)) / 2, $iDotSize * 1.5, $iDotSize * 1.5, $hBrush)
            Else
                _GDIPlus_BrushSetSolidColor($hBrush, 0xFFFFFFFF)
                _GDIPlus_GraphicsFillEllipse($hGfxCtxt, $iDotSize + $j * $iSpace, ($aCtrlSize[3] - $iDotSize) / 2, $iDotSize, $iDotSize, $hBrush)
            EndIf
            $j -= 1
        Next
        If $iProgress And $iProgress < 100 Then
            _GDIPlus_BrushSetSolidColor($hBrush, 0xFFFFFF00)
            Switch Mod($iFrame, 2)
                Case 0
                    _GDIPlus_GraphicsFillPie($hGfxCtxt, -$iDotSize * 3 + $iProgress * ($aCtrlSize[2] / $iScalar) / $iScalar, ($aCtrlSize[3] - $iDotSize * 2) / 2, $iDotSize * 2, $iDotSize * 2, 45, 270, $hBrush)
                Case Else
                    _GDIPlus_GraphicsFillEllipse($hGfxCtxt, -$iDotSize * 3 + $iProgress * ($aCtrlSize[2] / $iScalar) / $iScalar, ($aCtrlSize[3] - $iDotSize * 2) / 2, $iDotSize * 2, $iDotSize * 2, $hBrush)
            EndSwitch
            _GDIPlus_GraphicsFillEllipse($hGfxCtxt, -$iDotSize * 2 + $iProgress * ($aCtrlSize[2] / $iScalar) / $iScalar, $iDotSize / 5 + ($aCtrlSize[3] - $iDotSize * 2) / 2, $iDotSize / 4, $iDotSize / 4)
            If TimerDiff($iTimer) > 125 Then
                $iFrame += 1
                $iTimer = TimerInit()
            EndIf
        EndIf
    EndIf
    $hGDIBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    $hB = GUICtrlSendMsg($iCtrl, 0x0172, 0, $hGDIBmp)
    If $hB Then _WinAPI_DeleteObject($hB)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGfxCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _WinAPI_DeleteObject($hGDIBmp)
EndFunc
Link to comment
Share on other sites

Here is the code with the upper pacman as red and the lower as yellow, does anyone know the color codes for pink, blue, orange?

Thanks!

#include <StaticConstants.au3>
#include <GUIConstants.au3>
#include <GUIStatusBar.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>

_GDIPlus_Startup()
; 2D array to hold URL and filesize
Dim $arrDownload[5][2]
; Put the number of elements into element [0][0]
$arrDownload[0][0] = UBound($arrDownload) - 1
; Setup the files to download
$arrDownload[1][0] = "http://www.malwarebytes.org/mbam/program/mbam-setup.exe"
$arrDownload[2][0] = "http://www.spybotupdates.com/files/spybotsd162.exe"
$arrDownload[3][0] = "http://cdn.superantispyware.com/SUPERAntiSpyware.exe"
$arrDownload[4][0] = "http://download.piriform.com/ccsetup403.exe"
; ## GUI ######
$Form = GUICreate("Downloader", 400, 220)
$butStart = GUICtrlCreateButton("Start", 75, 15, 100, 30)
$installAll = GUICtrlCreateButton("Install All", 225, 15, 100, 30)
$txtCurrent = GUICtrlCreateLabel("Current File Progress:", 30, 55, 100, 20)
;~$prgCurrent = GUICtrlCreateProgress(30, 75, 300, 10)
$lblCurrent = GUICtrlCreateLabel("0%", 340, 72, 30, 15, $SS_RIGHT)
$txtOverall = GUICtrlCreateLabel("Overall Progress:", 30, 110, 80, 20)
;~ $prgOverall = GUICtrlCreateProgress(30, 125, 300, 10)
$prgCurrent = GUICtrlCreatePic("", 30, 75, 300, 30, $SS_SUNKEN)
$prgOverall = GUICtrlCreatePic("", 30, 125, 300, 30, $SS_SUNKEN)
$lblOverall = GUICtrlCreateLabel("0%", 340, 122, 30, 15, $SS_RIGHT)
$chkShutdown = GUICtrlCreateCheckbox("Shutdown PC when finished", 130, 170, 175, 20)
$StatusBar = _GUICtrlStatusBar_Create($Form)
_GUICtrlStatusBar_SetText($StatusBar, "Ready")
_GDIPlus_PacmanProgressbar(0, $prgOverall, $Form, 0xFFFF0000)
_GDIPlus_PacmanProgressbar(0, $prgCurrent, $Form, 0xFFFF0000)
GUISetState(@SW_SHOW)
; ## END GUI #####

While 1

    $nMsg = GUIGetMsg()

    If $nMsg = $GUI_EVENT_CLOSE Then
        GUIDelete()
        _GDIPlus_Shutdown()
        Exit
    EndIf

    If $nMsg = $butStart Then doDownloads()

    If $nMsg = $installAll Then doInstalls()

WEnd

Func doInstalls()
    ShellExecuteWait(@DesktopDir & "\AllInOne.exe")

EndFunc   ;==>doInstalls


Func doDownloads()
    ; Variables for calculating percentages
    Local $CurrentFileSize = 0
    Local $TotalFileSize = 0
    Local $currBytesDownloaded = 0
    Local $overallBytesDownloaded = 0
    Local $TotalBytesDownloaded = 0
    Local $currPercent = 0
    Local $overallPercent = 0
    Local $Filename = ""
    Local $currDownload
    Local $CancelPressed = False
    ; Change the Start button to Cancel
    GuiCtrlSetData($butStart, "Cancel")

    ; Reset all progress data
    GUICtrlSetData($lblOverall, "0%")
;~     GUICtrlSetData($prgOverall, "0")
    _GDIPlus_PacmanProgressbar(0, $prgOverall, $Form, 0xFFFF0000)

    GUICtrlSetData($lblCurrent, "0%")
    ;GUICtrlSetData($prgCurrent, "0")
        _GDIPlus_PacmanProgressbar(0, $prgCurrent, $Form, 0xFFFF0000)


    ; Loop through all the URLs to get all the FileSizes (this allows us to calculate overall progress of ALL downloads)
    For $i = 1 To UBound($arrDownload) - 1

        ; Get the filename from after the last forward slash
        $Filename = StringRight($arrDownload[$i][0], StringLen($arrDownload[$i][0]) - StringInStr($arrDownload[$i][0], "/", -1, -1))

        _GUICtrlStatusBar_SetText($StatusBar, 'Getting filesize for file "' & $Filename & '"...')

        ; Put the filesize into second column of array
        $CurrentFileSize = INetGetSize($arrDownload[$i][0])

        ; We're going to use this filesize twice so put it in a variable so we only actually look it up once
        $arrDownload[$i][1] = $CurrentFileSize
        ; Add this to the total file size
        $TotalFileSize += INetGetSize($arrDownload[$i][0])

    Next


    ; Now do the individual downloads
    For $i = 1 To UBound($arrDownload) - 1

        ; Reset current bytes
        $currBytesDownloaded = 0

        ; Reset the current progress bar
        GUICtrlSetData($lblCurrent, "0%")
        GUICtrlSetData($prgCurrent, "0")

        ; Get the filename from after the last forward slash
        $Filename = StringRight($arrDownload[$i][0], StringLen($arrDownload[$i][0]) - StringInStr($arrDownload[$i][0], "/", -1, -1))

        _GUICtrlStatusBar_SetText($StatusBar, 'Downloading "' & $Filename & '" (' & $i & '/' & UBound($arrDownload) - 1 & ')...')

        ; Start the download
        $currDownload = INetGet($arrDownload[$i][0], @ScriptDir & "\" & $Filename, 1, 1)

        Do
            ; Check for messages
            Local $dMsg = GUIGetMsg()

            ; If the press the 'Cancel button
            If $dMsg = $butStart Then

                ; Check they really want to cancel
                Local $Confirm_Cancel = MsgBox(4, "Downloader", "Do You Want To Cancel All Downloads?", 0, $Form)

                ; If they do want to cancel
                If $Confirm_Cancel = 6 Then

                    ; stop the download
                    INetClose($currDownload)

                    ; notify the outer loop to exit
                    $CancelPressed = True
                    ExitLoop
                EndIf

            EndIf

            ; Get Current Bytes downloaded
            $currBytesDownloaded = INetGetInfo($currDownload, 0)

            ; Add current bytes downloaded to the total filesize of completed downloads
            $overallBytesDownloaded = $TotalBytesDownloaded + $currBytesDownloaded

            ; Get the current percentages
            $currPercent = ($currBytesDownloaded / $arrDownload[$i][1]) * 100
            $overallPercent = ($overallBytesDownloaded / $TotalFileSize) * 100

            ; Update the current progress bar
            GUICtrlSetData($prgCurrent, $currPercent)
             _GDIPlus_PacmanProgressbar($currPercent, $prgCurrent, $Form,0xFFFF0F00)
;~             GUICtrlSetData($prgOverall, $overallPercent)
            _GDIPlus_PacmanProgressbar($overallPercent, $prgOverall, $Form,0xFFFFFF00)

            ; Update the progress labels only if they have changed (to avoid flicker)
            If GUICtrlRead($lblCurrent) <> floor($currPercent) & "%" Then GUICtrlSetData($lblCurrent, Floor($currPercent) & "%")
            If GUICtrlRead($lblOverall) <> floor($overallPercent) & "%" Then
                GUICtrlSetData($lblOverall, floor($overallPercent) & "%")
                WinSetTitle($Form, "", floor($overallPercent) & "% - Downloader")
            EndIf

        Until INetGetInfo($currDownload, 2)

        If Not $CancelPressed Then
            ; Set current progress to 100% here (sometimes gets stuck at 99 with rounding)
            GUICtrlSetData($prgCurrent, 100)
            GUICtrlSetData($lblCurrent, "100%")
        EndIf
        ; Add the filesize of this completed download to the total bytes downloaded
        $TotalBytesDownloaded += $arrDownload[$i][1]

        ; User cancelled - don't download anything else
        If $CancelPressed Then ExitLoop

    Next

    ; Reset the GUI labels
    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
    GUICtrlSetData($butStart, "Start")
    If $CancelPressed Then
        ; User cancelled
        MsgBox(48, "Downloader", "All downloads cancelled", 0, $Form)
    Else
        ; everything finished downloading

        ; Set current progress to 100% here (sometimes gets stuck at 99 with rounding)
        GUICtrlSetData($prgCurrent, 100)
        GUICtrlSetData($lblCurrent, "100%")


        ; Check if user wants us to shutdown
        If GUICtrlRead($chkShutdown) = $GUI_CHECKED Then
            ; Shutdown the PC if box is ticked and exit program
            Shutdown(29)
            Exit
        Else
            MsgBox(64, "Downloader", "All downloads complete", 0, $Form)
        EndIf

    EndIf
    ; Reset the window title
    WinSetTitle($Form, "", "Downloader")
EndFunc   ;==>doDownloads

Func _GDIPlus_PacmanProgressbar($iProgress, $iCtrl, $hGUI, $pacmanColor, $iProgressMax = 100, $iPackmanSpeed = 0.5, $iDotSize = 10, $iBGColor = 0xFF404040) ; coded by UEZ build 2013-07-26 beta
    Local $aResult, $hBitmap, $hGfxCtxt, $aCtrlSize, $hB, $hGDIBmp, $hBrush, $i, $iScalar = 10, $j = $iScalar - 1, $iSpace
    Local Static $iFrame = 0, $iTimer = TimerInit()
    $aCtrlSize = ControlGetPos($hGUI, "", $iCtrl)
    If @error Then Return SetError(1, 0, -1)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $aCtrlSize[2] - 2, "int", $aCtrlSize[3] - 2, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0)
    $hBitmap = $aResult[6]
    $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hGfxCtxt, $iBGColor)
    _GDIPlus_GraphicsSetSmoothingMode($hGfxCtxt, 2)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $iSpace = $aCtrlSize[2] / $iScalar
    If $iProgress < $iProgressMax Then
        For $i = ($iProgress / $iScalar) To $iScalar
            If $j = $iScalar - 1 Then
                _GDIPlus_BrushSetSolidColor($hBrush, 0xFFFF0000)
                _GDIPlus_GraphicsFillEllipse($hGfxCtxt, $iDotSize + $j * $iSpace, ($aCtrlSize[3] - (1.5 * $iDotSize)) / 2, $iDotSize * 1.5, $iDotSize * 1.5, $hBrush)
            Else
                _GDIPlus_BrushSetSolidColor($hBrush, 0xFFFFFFFF)
                _GDIPlus_GraphicsFillEllipse($hGfxCtxt, $iDotSize + $j * $iSpace, ($aCtrlSize[3] - $iDotSize) / 2, $iDotSize, $iDotSize, $hBrush)
            EndIf
            $j -= 1
        Next
        If $iProgress And $iProgress < 100 Then
            _GDIPlus_BrushSetSolidColor($hBrush, $pacmanColor) ;0xFFFFFF00
            Switch Mod($iFrame, 2)
                Case 0
                    _GDIPlus_GraphicsFillPie($hGfxCtxt, -$iDotSize * 3 + $iProgress * ($aCtrlSize[2] / $iScalar) / $iScalar, ($aCtrlSize[3] - $iDotSize * 2) / 2, $iDotSize * 2, $iDotSize * 2, 45, 270, $hBrush)
                Case Else
                    _GDIPlus_GraphicsFillEllipse($hGfxCtxt, -$iDotSize * 3 + $iProgress * ($aCtrlSize[2] / $iScalar) / $iScalar, ($aCtrlSize[3] - $iDotSize * 2) / 2, $iDotSize * 2, $iDotSize * 2, $hBrush)
            EndSwitch
            _GDIPlus_GraphicsFillEllipse($hGfxCtxt, -$iDotSize * 2 + $iProgress * ($aCtrlSize[2] / $iScalar) / $iScalar, $iDotSize / 5 + ($aCtrlSize[3] - $iDotSize * 2) / 2, $iDotSize / 4, $iDotSize / 4)
            If TimerDiff($iTimer) > 125 Then
                $iFrame += 1
                $iTimer = TimerInit()
            EndIf
        EndIf
    EndIf
    $hGDIBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    $hB = GUICtrlSendMsg($iCtrl, 0x0172, 0, $hGDIBmp)
    If $hB Then _WinAPI_DeleteObject($hB)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGfxCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _WinAPI_DeleteObject($hGDIBmp)
EndFunc
Link to comment
Share on other sites

Colors in AutoIt are hexadecimal strings with 2 digits for red, then 2 for green, then 2 for blue.  It looks like "0xRRGGBB" when you put it together, but replace "RR" with the red color value (00 [darkest] to FF [brightest]), and the same for GG and BB.

Blue is easy.  It's 0x0000FF.  Or, if that's too bright, 0x0000A0.

Pink is like red, but it's lighter.  So try something like 0xFF9090.  (Full red, and a good amount of green & blue to brighten it up.)

I'll let you figure out orange, but here's a hint: Lots of red and a good amount of green.

Edited by Artisan
Link to comment
Share on other sites

Okay so right now I have those colors in an array, but when I run my program it just shows a tiny black dot (like 1/100 the size of the pacman) going across...It doesnt change the color at all.

Here is part of the code I added..

Dim $colorArray[5]

$colorArray[0] = 0x0000A0
$colorArray[1] = 0x0000FF ;blue
$colorArray[2] = 0xFF00FF ;pink
$colorArray[3] = 0xFF0000 ;red
$colorArray[4] = 0x00FF00 ;green


For $i = 1 To UBound($arrDownload) - 1
      $color = $colorArray[$i]
       _GDIPlus_PacmanProgressbar($currPercent, $prgCurrent, $Form,$color)
Next
Link to comment
Share on other sites

Okay I figured it out by trial and error, but weird that the color mixer doesn't work for some reason...

#include <StaticConstants.au3>
#include <GUIConstants.au3>
#include <GUIStatusBar.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>

_GDIPlus_Startup()
; 2D array to hold URL and filesize
Dim $arrDownload[5][2]
; Put the number of elements into element [0][0]
$arrDownload[0][0] = UBound($arrDownload) - 1
; Setup the files to download
$arrDownload[1][0] = "http://www.malwarebytes.org/mbam/program/mbam-setup.exe"
$arrDownload[2][0] = "http://www.spybotupdates.com/files/spybotsd162.exe"
$arrDownload[3][0] = "http://cdn.superantispyware.com/SUPERAntiSpyware.exe"
$arrDownload[4][0] = "http://download.piriform.com/ccsetup403.exe"
; ## GUI ######
$Form = GUICreate("Downloader", 400, 220)
$butStart = GUICtrlCreateButton("Start", 75, 15, 100, 30)
$installAll = GUICtrlCreateButton("Install All", 225, 15, 100, 30)
$txtCurrent = GUICtrlCreateLabel("Current File Progress:", 30, 55, 100, 20)
;~$prgCurrent = GUICtrlCreateProgress(30, 75, 300, 10)
$lblCurrent = GUICtrlCreateLabel("0%", 340, 72, 30, 15, $SS_RIGHT)
$txtOverall = GUICtrlCreateLabel("Overall Progress:", 30, 110, 80, 20)
;~ $prgOverall = GUICtrlCreateProgress(30, 125, 300, 10)
$prgCurrent = GUICtrlCreatePic("", 30, 75, 300, 30, $SS_SUNKEN)
$prgOverall = GUICtrlCreatePic("", 30, 125, 300, 30, $SS_SUNKEN)
$lblOverall = GUICtrlCreateLabel("0%", 340, 122, 30, 15, $SS_RIGHT)
$chkShutdown = GUICtrlCreateCheckbox("Shutdown PC when finished", 130, 170, 175, 20)
$StatusBar = _GUICtrlStatusBar_Create($Form)
_GUICtrlStatusBar_SetText($StatusBar, "Ready")
_GDIPlus_PacmanProgressbar(0, $prgOverall, $Form, 0xFFFF0000)
_GDIPlus_PacmanProgressbar(0, $prgCurrent, $Form, 0xFFFF0000)
GUISetState(@SW_SHOW)
; ## END GUI #####
Dim $colorArray[5]
;0xFFFFFFFF white
;0xFF000000 black

$colorArray[1] = 0xFF0000FF ;blue
$colorArray[2] = 0xffffafff ;pink
$colorArray[3] = 0xFFFF0000 ;red
$colorArray[4] = 0xFF00FF00 ;green

While 1

    $nMsg = GUIGetMsg()

    If $nMsg = $GUI_EVENT_CLOSE Then
        GUIDelete()
        _GDIPlus_Shutdown()
        Exit
    EndIf

    If $nMsg = $butStart Then doDownloads()

    If $nMsg = $installAll Then doInstalls()

WEnd

Func doInstalls()
    ShellExecuteWait(@DesktopDir & "\AllInOne.exe")

EndFunc   ;==>doInstalls


Func doDownloads()
    ; Variables for calculating percentages
    Local $CurrentFileSize = 0
    Local $TotalFileSize = 0
    Local $currBytesDownloaded = 0
    Local $overallBytesDownloaded = 0
    Local $TotalBytesDownloaded = 0
    Local $currPercent = 0
    Local $overallPercent = 0
    Local $Filename = ""
    Local $currDownload
    Local $CancelPressed = False
    ; Change the Start button to Cancel
    GuiCtrlSetData($butStart, "Cancel")

    ; Reset all progress data
    GUICtrlSetData($lblOverall, "0%")
;~     GUICtrlSetData($prgOverall, "0")
    _GDIPlus_PacmanProgressbar(0, $prgOverall, $Form, 0xFFFF0000)

    GUICtrlSetData($lblCurrent, "0%")
    ;GUICtrlSetData($prgCurrent, "0")
        _GDIPlus_PacmanProgressbar(0, $prgCurrent, $Form, 0xFFFF0000)


    ; Loop through all the URLs to get all the FileSizes (this allows us to calculate overall progress of ALL downloads)
    For $i = 1 To UBound($arrDownload) - 1
        ; Get the filename from after the last forward slash
        $Filename = StringRight($arrDownload[$i][0], StringLen($arrDownload[$i][0]) - StringInStr($arrDownload[$i][0], "/", -1, -1))

        _GUICtrlStatusBar_SetText($StatusBar, 'Getting filesize for file "' & $Filename & '"...')

        ; Put the filesize into second column of array
        $CurrentFileSize = INetGetSize($arrDownload[$i][0])

        ; We're going to use this filesize twice so put it in a variable so we only actually look it up once
        $arrDownload[$i][1] = $CurrentFileSize
        ; Add this to the total file size
        $TotalFileSize += INetGetSize($arrDownload[$i][0])

    Next


    ; Now do the individual downloads
    For $i = 1 To UBound($arrDownload) - 1

        ; Reset current bytes
        $currBytesDownloaded = 0

        ; Reset the current progress bar
        GUICtrlSetData($lblCurrent, "0%")
        GUICtrlSetData($prgCurrent, "0")

        ; Get the filename from after the last forward slash
        $Filename = StringRight($arrDownload[$i][0], StringLen($arrDownload[$i][0]) - StringInStr($arrDownload[$i][0], "/", -1, -1))

        _GUICtrlStatusBar_SetText($StatusBar, 'Downloading "' & $Filename & '" (' & $i & '/' & UBound($arrDownload) - 1 & ')...')

        ; Start the download
        $currDownload = INetGet($arrDownload[$i][0], @ScriptDir & "\" & $Filename, 1, 1)

        Do
            $color = $colorArray[$i]
            ; Check for messages
            Local $dMsg = GUIGetMsg()

            ; If the press the 'Cancel button
            If $dMsg = $butStart Then

                ; Check they really want to cancel
                Local $Confirm_Cancel = MsgBox(4, "Downloader", "Do You Want To Cancel All Downloads?", 0, $Form)

                ; If they do want to cancel
                If $Confirm_Cancel = 6 Then

                    ; stop the download
                    INetClose($currDownload)

                    ; notify the outer loop to exit
                    $CancelPressed = True
                    ExitLoop
                EndIf

            EndIf

            ; Get Current Bytes downloaded
            $currBytesDownloaded = INetGetInfo($currDownload, 0)

            ; Add current bytes downloaded to the total filesize of completed downloads
            $overallBytesDownloaded = $TotalBytesDownloaded + $currBytesDownloaded

            ; Get the current percentages
            $currPercent = ($currBytesDownloaded / $arrDownload[$i][1]) * 100
            $overallPercent = ($overallBytesDownloaded / $TotalFileSize) * 100

            ; Update the current progress bar
            GUICtrlSetData($prgCurrent, $currPercent)
             _GDIPlus_PacmanProgressbar($currPercent, $prgCurrent, $Form,  $color)
;~             GUICtrlSetData($prgOverall, $overallPercent)
            _GDIPlus_PacmanProgressbar($overallPercent, $prgOverall, $Form,0xFFFFFF00)

            ; Update the progress labels only if they have changed (to avoid flicker)
            If GUICtrlRead($lblCurrent) <> floor($currPercent) & "%" Then GUICtrlSetData($lblCurrent, Floor($currPercent) & "%")
            If GUICtrlRead($lblOverall) <> floor($overallPercent) & "%" Then
                GUICtrlSetData($lblOverall, floor($overallPercent) & "%")
                WinSetTitle($Form, "", floor($overallPercent) & "% - Downloader")
            EndIf

        Until INetGetInfo($currDownload, 2)

        If Not $CancelPressed Then
            ; Set current progress to 100% here (sometimes gets stuck at 99 with rounding)
            GUICtrlSetData($prgCurrent, 100)
            GUICtrlSetData($lblCurrent, "100%")
        EndIf
        ; Add the filesize of this completed download to the total bytes downloaded
        $TotalBytesDownloaded += $arrDownload[$i][1]

        ; User cancelled - don't download anything else
        If $CancelPressed Then ExitLoop

    Next

    ; Reset the GUI labels
    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
    GUICtrlSetData($butStart, "Start")
    If $CancelPressed Then
        ; User cancelled
        MsgBox(48, "Downloader", "All downloads cancelled", 0, $Form)
    Else
        ; everything finished downloading

        ; Set current progress to 100% here (sometimes gets stuck at 99 with rounding)
        GUICtrlSetData($prgCurrent, 100)
        GUICtrlSetData($lblCurrent, "100%")


        ; Check if user wants us to shutdown
        If GUICtrlRead($chkShutdown) = $GUI_CHECKED Then
            ; Shutdown the PC if box is ticked and exit program
            Shutdown(29)
            Exit
        Else
            MsgBox(64, "Downloader", "All downloads complete", 0, $Form)
        EndIf

    EndIf
    ; Reset the window title
    WinSetTitle($Form, "", "Downloader")
EndFunc   ;==>doDownloads

Func _GDIPlus_PacmanProgressbar($iProgress, $iCtrl, $hGUI, $pacmanColor, $iProgressMax = 100, $iPackmanSpeed = 0.5, $iDotSize = 10, $iBGColor = 0xFF404040) ; coded by UEZ build 2013-07-26 beta
    Local $aResult, $hBitmap, $hGfxCtxt, $aCtrlSize, $hB, $hGDIBmp, $hBrush, $i, $iScalar = 10, $j = $iScalar - 1, $iSpace
    Local Static $iFrame = 0, $iTimer = TimerInit()
    $aCtrlSize = ControlGetPos($hGUI, "", $iCtrl)
    If @error Then Return SetError(1, 0, -1)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $aCtrlSize[2] - 2, "int", $aCtrlSize[3] - 2, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0)
    $hBitmap = $aResult[6]
    $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hGfxCtxt, $iBGColor)
    _GDIPlus_GraphicsSetSmoothingMode($hGfxCtxt, 2)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $iSpace = $aCtrlSize[2] / $iScalar
    If $iProgress < $iProgressMax Then
        For $i = ($iProgress / $iScalar) To $iScalar
            If $j = $iScalar - 1 Then
                _GDIPlus_BrushSetSolidColor($hBrush, 0xFFFF0000)
                _GDIPlus_GraphicsFillEllipse($hGfxCtxt, $iDotSize + $j * $iSpace, ($aCtrlSize[3] - (1.5 * $iDotSize)) / 2, $iDotSize * 1.5, $iDotSize * 1.5, $hBrush)
            Else
                _GDIPlus_BrushSetSolidColor($hBrush, 0xFFFFFFFF)
                _GDIPlus_GraphicsFillEllipse($hGfxCtxt, $iDotSize + $j * $iSpace, ($aCtrlSize[3] - $iDotSize) / 2, $iDotSize, $iDotSize, $hBrush)
            EndIf
            $j -= 1
        Next
        If $iProgress And $iProgress < 100 Then
            _GDIPlus_BrushSetSolidColor($hBrush, $pacmanColor) ;0xFFFFFF00
            Switch Mod($iFrame, 2)
                Case 0
                    _GDIPlus_GraphicsFillPie($hGfxCtxt, -$iDotSize * 3 + $iProgress * ($aCtrlSize[2] / $iScalar) / $iScalar, ($aCtrlSize[3] - $iDotSize * 2) / 2, $iDotSize * 2, $iDotSize * 2, 45, 270, $hBrush)
                Case Else
                    _GDIPlus_GraphicsFillEllipse($hGfxCtxt, -$iDotSize * 3 + $iProgress * ($aCtrlSize[2] / $iScalar) / $iScalar, ($aCtrlSize[3] - $iDotSize * 2) / 2, $iDotSize * 2, $iDotSize * 2, $hBrush)
            EndSwitch
            _GDIPlus_GraphicsFillEllipse($hGfxCtxt, -$iDotSize * 2 + $iProgress * ($aCtrlSize[2] / $iScalar) / $iScalar, $iDotSize / 5 + ($aCtrlSize[3] - $iDotSize * 2) / 2, $iDotSize / 4, $iDotSize / 4)
            If TimerDiff($iTimer) > 125 Then
                $iFrame += 1
                $iTimer = TimerInit()
            EndIf
        EndIf
    EndIf
    $hGDIBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    $hB = GUICtrlSendMsg($iCtrl, 0x0172, 0, $hGDIBmp)
    If $hB Then _WinAPI_DeleteObject($hB)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGfxCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _WinAPI_DeleteObject($hGDIBmp)
EndFunc
Link to comment
Share on other sites

Okay I figured it out by trial and error, but weird that the color mixer doesn't work for some reason...

 

The reason for that is transparency.  The color mixer gives the regular 0xRRGGBB color values.  Transparency is an extra 2 hex digits indicating how solid/opaque to make the color.  With transparency (T) the color is 0xTTRRGGBB.  That's why you needed to add the extra FF to your colors.  The black dot you saw was likely packman's eye or something, but I haven't tested your code so I can't say for certain.

Link to comment
Share on other sites

I changed the _GDIPlus_PacmanProgressbar() again because I didn't like the previous one.

Please use this function.

#include <StaticConstants.au3>
#include <GUIConstants.au3>
#include <GUIStatusBar.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>

_GDIPlus_Startup()
; 2D array to hold URL and filesize
Dim $arrDownload[5][2]
; Put the number of elements into element [0][0]
$arrDownload[0][0] = UBound($arrDownload) - 1
; Setup the files to download
$arrDownload[1][0] = "http://www.malwarebytes.org/mbam/program/mbam-setup.exe"
$arrDownload[2][0] = "http://www.spybotupdates.com/files/spybotsd162.exe"
$arrDownload[3][0] = "http://cdn.superantispyware.com/SUPERAntiSpyware.exe"
$arrDownload[4][0] = "http://download.piriform.com/ccsetup403.exe"
; ## GUI ######
$Form = GUICreate("Downloader", 400, 220)
$butStart = GUICtrlCreateButton("Start", 75, 15, 100, 30)
$installAll = GUICtrlCreateButton("Install All", 225, 15, 100, 30)
$txtCurrent = GUICtrlCreateLabel("Current File Progress:", 30, 55, 100, 20)
;~$prgCurrent = GUICtrlCreateProgress(30, 75, 300, 10)
$lblCurrent = GUICtrlCreateLabel("0%", 340, 72, 30, 15, $SS_RIGHT)
$txtOverall = GUICtrlCreateLabel("Overall Progress:", 30, 110, 80, 20)
;~ $prgOverall = GUICtrlCreateProgress(30, 125, 300, 10)
$prgCurrent = GUICtrlCreatePic("", 30, 75, 300, 30, $SS_SUNKEN)
$prgOverall = GUICtrlCreatePic("", 30, 125, 300, 30, $SS_SUNKEN)
$lblOverall = GUICtrlCreateLabel("0%", 340, 122, 30, 15, $SS_RIGHT)
$chkShutdown = GUICtrlCreateCheckbox("Shutdown PC when finished", 130, 170, 175, 20)
$StatusBar = _GUICtrlStatusBar_Create($Form)
_GUICtrlStatusBar_SetText($StatusBar, "Ready")
_GDIPlus_PacmanProgressbar(0, $prgOverall, $Form, 0xFFFF0000)
_GDIPlus_PacmanProgressbar(0, $prgCurrent, $Form, 0xFFFF0000)
GUISetState(@SW_SHOW)
; ## END GUI #####
Dim $colorArray[5]
;0xFFFFFFFF white
;0xFF000000 black

$colorArray[1] = 0xFF0000FF ;blue
$colorArray[2] = 0xffffafff ;pink
$colorArray[3] = 0xFFFF0000 ;red
$colorArray[4] = 0xFF00FF00 ;green

While 1

    $nMsg = GUIGetMsg()

    If $nMsg = $GUI_EVENT_CLOSE Then
        GUIDelete()
        _GDIPlus_Shutdown()
        Exit
    EndIf

    If $nMsg = $butStart Then doDownloads()

    If $nMsg = $installAll Then doInstalls()

WEnd

Func doInstalls()
    ShellExecuteWait(@DesktopDir & "\AllInOne.exe")

EndFunc   ;==>doInstalls


Func doDownloads()
    ; Variables for calculating percentages
    Local $CurrentFileSize = 0
    Local $TotalFileSize = 0
    Local $currBytesDownloaded = 0
    Local $overallBytesDownloaded = 0
    Local $TotalBytesDownloaded = 0
    Local $currPercent = 0
    Local $overallPercent = 0
    Local $Filename = ""
    Local $currDownload
    Local $CancelPressed = False
    ; Change the Start button to Cancel
    GuiCtrlSetData($butStart, "Cancel")

    ; Reset all progress data
    GUICtrlSetData($lblOverall, "0%")
;~     GUICtrlSetData($prgOverall, "0")
    _GDIPlus_PacmanProgressbar(0, $prgOverall, $Form, 0xFFFF0000)

    GUICtrlSetData($lblCurrent, "0%")
    ;GUICtrlSetData($prgCurrent, "0")
        _GDIPlus_PacmanProgressbar(0, $prgCurrent, $Form, 0xFFFF0000)


    ; Loop through all the URLs to get all the FileSizes (this allows us to calculate overall progress of ALL downloads)
    For $i = 1 To UBound($arrDownload) - 1
        ; Get the filename from after the last forward slash
        $Filename = StringRight($arrDownload[$i][0], StringLen($arrDownload[$i][0]) - StringInStr($arrDownload[$i][0], "/", -1, -1))

        _GUICtrlStatusBar_SetText($StatusBar, 'Getting filesize for file "' & $Filename & '"...')

        ; Put the filesize into second column of array
        $CurrentFileSize = INetGetSize($arrDownload[$i][0])

        ; We're going to use this filesize twice so put it in a variable so we only actually look it up once
        $arrDownload[$i][1] = $CurrentFileSize
        ; Add this to the total file size
        $TotalFileSize += INetGetSize($arrDownload[$i][0])

    Next


    ; Now do the individual downloads
    For $i = 1 To UBound($arrDownload) - 1

        ; Reset current bytes
        $currBytesDownloaded = 0

        ; Reset the current progress bar
        GUICtrlSetData($lblCurrent, "0%")
        GUICtrlSetData($prgCurrent, "0")

        ; Get the filename from after the last forward slash
        $Filename = StringRight($arrDownload[$i][0], StringLen($arrDownload[$i][0]) - StringInStr($arrDownload[$i][0], "/", -1, -1))

        _GUICtrlStatusBar_SetText($StatusBar, 'Downloading "' & $Filename & '" (' & $i & '/' & UBound($arrDownload) - 1 & ')...')

        ; Start the download
        $currDownload = INetGet($arrDownload[$i][0], @ScriptDir & "\" & $Filename, 1, 1)

        Do
            $color = $colorArray[$i]
            ; Check for messages
            Local $dMsg = GUIGetMsg()

            ; If the press the 'Cancel button
            If $dMsg = $butStart Then

                ; Check they really want to cancel
                Local $Confirm_Cancel = MsgBox(4, "Downloader", "Do You Want To Cancel All Downloads?", 0, $Form)

                ; If they do want to cancel
                If $Confirm_Cancel = 6 Then

                    ; stop the download
                    INetClose($currDownload)

                    ; notify the outer loop to exit
                    $CancelPressed = True
                    ExitLoop
                EndIf

            EndIf

            ; Get Current Bytes downloaded
            $currBytesDownloaded = INetGetInfo($currDownload, 0)

            ; Add current bytes downloaded to the total filesize of completed downloads
            $overallBytesDownloaded = $TotalBytesDownloaded + $currBytesDownloaded

            ; Get the current percentages
            $currPercent = ($currBytesDownloaded / $arrDownload[$i][1]) * 100
            $overallPercent = ($overallBytesDownloaded / $TotalFileSize) * 100

            ; Update the current progress bar
            GUICtrlSetData($prgCurrent, $currPercent)
             _GDIPlus_PacmanProgressbar($currPercent, $prgCurrent, $Form,  $color)
;~             GUICtrlSetData($prgOverall, $overallPercent)
            _GDIPlus_PacmanProgressbar($overallPercent, $prgOverall, $Form,0xFFFFFF00)

            ; Update the progress labels only if they have changed (to avoid flicker)
            If GUICtrlRead($lblCurrent) <> floor($currPercent) & "%" Then GUICtrlSetData($lblCurrent, Floor($currPercent) & "%")
            If GUICtrlRead($lblOverall) <> floor($overallPercent) & "%" Then
                GUICtrlSetData($lblOverall, floor($overallPercent) & "%")
                WinSetTitle($Form, "", floor($overallPercent) & "% - Downloader")
            EndIf

        Until INetGetInfo($currDownload, 2)

        If Not $CancelPressed Then
            ; Set current progress to 100% here (sometimes gets stuck at 99 with rounding)
            GUICtrlSetData($prgCurrent, 100)
            GUICtrlSetData($lblCurrent, "100%")
        EndIf
        ; Add the filesize of this completed download to the total bytes downloaded
        $TotalBytesDownloaded += $arrDownload[$i][1]

        ; User cancelled - don't download anything else
        If $CancelPressed Then ExitLoop

    Next

    ; Reset the GUI labels
    _GUICtrlStatusBar_SetText($StatusBar, "Ready")
    GUICtrlSetData($butStart, "Start")
    If $CancelPressed Then
        ; User cancelled
        MsgBox(48, "Downloader", "All downloads cancelled", 0, $Form)
    Else
        ; everything finished downloading

        ; Set current progress to 100% here (sometimes gets stuck at 99 with rounding)
        GUICtrlSetData($prgCurrent, 100)
        GUICtrlSetData($lblCurrent, "100%")


        ; Check if user wants us to shutdown
        If GUICtrlRead($chkShutdown) = $GUI_CHECKED Then
            ; Shutdown the PC if box is ticked and exit program
            Shutdown(29)
            Exit
        Else
            MsgBox(64, "Downloader", "All downloads complete", 0, $Form)
        EndIf

    EndIf
    ; Reset the window title
    WinSetTitle($Form, "", "Downloader")
EndFunc   ;==>doDownloads

Func _GDIPlus_PacmanProgressbar($iProgress, $iCtrl, $hGUI, $iPackmanColor, $iProgressMax = 100, $iScalar = 15, $iDotSize = 0, $iPackmanSpeed = 0.5, $iBGColor = 0xFF404040) ; coded by UEZ build 2013-07-27 beta
    Local $aResult, $hBitmap, $hGfxCtxt, $aCtrlSize, $hB, $hGDIBmp, $hBrush, $i, $fSpace, $iX, $fDX, $iPackmanSize
    Local Static $iFrame = 0, $iTimer = TimerInit()
    $aCtrlSize = ControlGetPos($hGUI, "", $iCtrl)
    If @error Then Return SetError(1, 0, -1)
    ;-2 because of control frame
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $aCtrlSize[2] - 2, "int", $aCtrlSize[3] - 2, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0)
    $hBitmap = $aResult[6]
    $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsClear($hGfxCtxt, $iBGColor)
    _GDIPlus_GraphicsSetSmoothingMode($hGfxCtxt, 2)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    If Not $iDotSize Then $iDotSize = ($aCtrlSize[3] - 2) / 4
    $iPackmanSize = $iDotSize * 2
    $fSpace = $aCtrlSize[2] / $iScalar
    $fDX = (($aCtrlSize[2] - 2) - ($fSpace * $iScalar - $fSpace + $iDotSize)) / 2
    If $iProgress < $iProgressMax Then
        For $i = Int($iProgress / 100 * $iScalar) To $iScalar
            $iX = $fDX + $fSpace * $i
            If $i = $iScalar - 1 Then _GDIPlus_BrushSetSolidColor($hBrush, 0xFFFF0000)
            _GDIPlus_GraphicsFillEllipse($hGfxCtxt, $iX, (($aCtrlSize[3] - 2) - $iDotSize) / 2, $iDotSize, $iDotSize, $hBrush)
        Next
        _GDIPlus_BrushSetSolidColor($hBrush, $iPackmanColor)
        $iX = -$fSpace + $fDX + ($iProgress / $iScalar / 100) * $iScalar * ($aCtrlSize[2] - 2)
        Switch Mod($iFrame, 2)
            Case 0
                DllCall($ghGDIPDll, "int", "GdipFillPie", "handle", $hGfxCtxt, "handle", $hBrush, "float", $iX, "float", (($aCtrlSize[3] - 2) - $iPackmanSize) / 2, "float", $iPackmanSize, "float", $iPackmanSize, "float", 45, "float", 270)
            Case Else
                DllCall($ghGDIPDll, "int", "GdipFillEllipse", "handle", $hGfxCtxt, "handle", $hBrush, "float", $iX, "float", (($aCtrlSize[3] - 2) - $iPackmanSize) / 2, "float", $iPackmanSize, "float", $iPackmanSize)
        EndSwitch
        _GDIPlus_BrushSetSolidColor($hBrush, 0xFF000000)
        DllCall($ghGDIPDll, "int", "GdipFillEllipse", "handle", $hGfxCtxt, "handle", $hBrush, "float", $iX + $iDotSize, "float", $iDotSize / 5 + ($aCtrlSize[3] - $iDotSize * 2) / 2, "float", $iDotSize / 4, "float", $iDotSize / 4)
        If TimerDiff($iTimer) > 125 Then
            $iFrame += 1
            $iTimer = TimerInit()
        EndIf
    EndIf
    $hGDIBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    $hB = GUICtrlSendMsg($iCtrl, 0x0172, 0, $hGDIBmp)
    If $hB Then _WinAPI_DeleteObject($hB)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGfxCtxt)
    _GDIPlus_BitmapDispose($hBitmap)
    _WinAPI_DeleteObject($hGDIBmp)
EndFunc   ;==>_GDIPlus_PacmanProgressbar
I will update my code also from your >previous topic

 

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...