DigDeep

Get Progress Bar in GUI

4 posts in this topic

I would need some urgent help here please...

Activities performed below:

Start button pressed > GUI Lable shows Text message > activities start > When download starts, it shows the Progressbar with the Filesize remaining and Percentage completed and Progressbar moving.

All the above activites happen except the Progressbar does not show any progress nor any Percentage and filesize.

For some reason, I am not able to fit the _GetDisplaySize  after the $Totalsize1.

 

#RequireAdmin
#NoTrayIcon


#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <ProgressConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $iPlaces

Func _GetDisplaySize($iTotalDownloaded, Const $iPlaces) ; Get file size
    Local Static $aSize[4] = ["Bytes remaining...", "KB remaining...", "MB remaining...", "GB remaining..."]
    For $i = 0 To 3
        $iTotalDownloaded /= 1024
        If (Int($iTotalDownloaded) = 0) Then Return Round($iTotalDownloaded * 1024, $iPlaces) & " " & $aSize[$i]
    Next
EndFunc   ;==>_GetDisplaySize

Func VLC()
$Lable1 = GUICtrlCreateLabel(@CRLF & @CRLF & 'Installing VLC Player...', 232, 112, 345, 193)
                    GUICtrlSetFont(-1, 11, 400, 0, "Arial")

    Local $sfldr = "C:\Temp"
        DirCreate($sfldr)
                Local $Src = "http://get.videolan.org/vlc/2.2.4/win32/vlc-2.2.4-win32.exe" ;Set URL
                $Dest = $sfldr & '\vlc.exe' ;Set folder
        $Down = InetGet($Src, $Dest, 1, 1) ;Forces a reload from the remote site and return immediately and download in the background
        $SrcSize1 = InetGetSize($Src) ;Get file size

     Local $idProgressbar1 = GUICtrlCreateProgress(288, 256, 238, 17)
    GUICtrlSetColor(-1, 32250); not working with Windows XP Style

While Not InetGetInfo($Down, 2) ;Loop until download is finished
        Sleep(3000) ;Sleep for half a second to avoid flicker in the progress bar
        $GetBytes1 = InetGetInfo($Down, 0) ;Get bytes received
        $Percentage1 = Int($GetBytes1 / $SrcSize1 * 100) ;Calculate percentage
        $Totalsize1 = $SrcSize1 - $GetBytes1
WEnd
EndFunc


$Form2 = GUICreate("Form2", 626, 491, 466, 301)
$Start = GUICtrlCreateButton("Start", 264, 416, 75, 25)
$Label1 = GUICtrlCreateLabel("Label1", 112, 40, 388, 361)
    GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit

        Case $nMsg = $Start
VLC()

    EndSelect
WEnd

 

Share this post


Link to post
Share on other sites



I added the below line and now I am able to see the Progressbar moving along with the download. But I am still not able to figure out the _GetDisplaySize...

$Totalsize1 = $SrcSize1 - $GetBytes1
GUICtrlSetData($idProgressbar1, $Percentage1)

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try this:

#RequireAdmin
#NoTrayIcon

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <ProgressConstants.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $iPlaces

main()

Func main()

    $Form2 = GUICreate("Form2", 626, 491, 466, 301)
    $Start = GUICtrlCreateButton("Start", 264, 416, 75, 25)
    $Label1 = GUICtrlCreateLabel("Label1", 112, 40, 388, 361)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $GUI_EVENT_CLOSE
                Exit
            Case $nMsg = $Start
                VLC()
        EndSelect
    WEnd
EndFunc

Func VLC()
    $Lable1 = GUICtrlCreateLabel(@CRLF & @CRLF & 'Installing VLC Player...', 232, 112, 345, 193)
    $LBL_Percent = GUICtrlCreateLabel("0%", 232, 256, 45, 30)
    GUICtrlSetFont(-1, 11, 400, 0, "Arial")
    Local $sfldr = "C:\Temp"
    DirCreate($sfldr)
    Local $Src = "http://get.videolan.org/vlc/2.2.4/win32/vlc-2.2.4-win32.exe" ;Set URL
    $Dest = $sfldr & '\vlc.exe' ;Set folder
    $Down = InetGet($Src, $Dest, 1, 1)
    $SrcSize1 = InetGetSize($Src) ;Get file size
    Local $idProgressbar1 = GUICtrlCreateProgress(288, 256, 238, 17)
    GUICtrlSetColor(-1, 32250); not working with Windows XP Style
    Local $Size = InetGetSize($Src,1) ;get the size of the update
    While Not InetGetInfo($Down, 2)
        Local $Percent = Round((InetGetInfo($Down,0)/$Size)*100,1)
        GUICtrlSetData($idProgressbar1,$Percent)
        GUICtrlSetData($LBL_Percent,$Percent & "%")
        Sleep(100)
    WEnd
    GUICtrlSetData($Lable1,"Download Complete")
EndFunc

 

Edited by R0G

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