Sign in to follow this  
Followers 0
ss3vegeta

Double Progress Bar

8 posts in this topic

Hello,

I've created a small program that installs a list of user selected software. The program works, but it takes a very long time for some of the software to install. So people think that it is frozen when in fact it isn't.

Here is the function I use to install and display a progress bar:

; This function peforms the install and displays the progress bar.
Func InstallAndDisplayProgress($arraySize, $installFlag, $arrInstallKey)
    ProgressOn("Installing", "This could take a while!", "Working")
    $loop = 0
    $ProgressFlag = 0
    
    While $loop < $arraySize
        If $programs[$loop][$arrInstallKey] = $installFlag Then
            RunWait("Installers/" & $programs[$loop][$arrFileName])
            $ProgressFlag = $ProgressFlag + 1
            ProgressSet( Ceiling(($ProgressFlag/$numberOfSoftwareSelected) * 100), $ProgressFlag & " of " & $numberOfSoftwareSelected & " programs installed so far.")
        EndIf
        $loop = $loop + 1
    WEnd
    ProgressSet(100, "Installation Complete")
    Sleep(2500)
    ProgressOff()
EndFunc

What I'm wondering is if there is a way to create a double progress bar in the same window. Basically the top one just being a constant scan so that the program doesn't look like it's frozen and the bottom one tracking the progress of the programs installed, like the current one does. By constant scan I simply mean that the top one just slides from left to right every few seconds so there is some movement and people don't complain that the program is frozen.

Any advice is appreciated,

ss3

Share this post


Link to post
Share on other sites



Thanks for the reply. I'll check this out, hopefully I understand it.

Share this post


Link to post
Share on other sites

like this

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Form1", 321, 239, 193, 125)
$Progress1 = GUICtrlCreateProgress(48, 48, 209, 33)
$Progress2 = GUICtrlCreateProgress(48, 96, 209, 41)
GUISetState(@SW_SHOW)

AdlibEnable("prog2",50)
while 1
for $x=1 to 100
    GUICtrlSetData($Progress1,$x)
    sleep(50)

    Next
    sleep(50)
WEnd    

Func prog2()
$rnd=Random(0,100,0)
GUICtrlSetData($Progress2,$rnd)
sleep(25)
EndFunc

Share this post


Link to post
Share on other sites

rasim's UDF of course :)

But for only 2 progresses may be, it's enough:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
Global $nDetail = 10 ; count of install steps

$Form1 = GUICreate("Form1", 400, 200)
GUICtrlCreateLabel('current: ', 10, 43, 60, 17)
$ProgressDetail = GUICtrlCreateProgress(75, 40, 315, 20, 0x01)
GUICtrlCreateLabel('sum: ', 10, 73, 60, 17)
$ProgressSum = GUICtrlCreateProgress(75, 70, 315, 20, 0x01)
GUISetState(@SW_SHOW)

_SetProgress()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SetProgress()
    Local $stepSum = Floor(100/$nDetail)
    Local $cntDetail, $cntSum = 0, $stepDetail, $cntFile
    For $i = 1 To $nDetail ; loop for progress-sum
        $cntDetail = 0
        $cntFile = 25
        $stepDetail = Floor(100/$cntFile)  ; step-width for install-steps, i.e. Floor(100/file count)
        For $j = 1 To $cntFile ; inner loop for installation, filecopy or whatever
            ; i.e. FileCopy
            Sleep(20)
            $cntDetail += $stepDetail
            GUICtrlSetData($ProgressDetail, $cntDetail)
        Next
        GUICtrlSetData($ProgressDetail, 100)
        Sleep(100)
        $cntSum += $stepSum
        GUICtrlSetData($ProgressSum, $cntSum)
    Next
    GUICtrlSetData($ProgressSum, 100)
EndFunc

Best Regards BugFix  

Share this post


Link to post
Share on other sites

not sure how to use progress bars yet, but will this help?

can you make the bar increment from the right? that would be another minor change to this example to make it closer to what you say you want.

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

$count=1
$x=0
$increment=0
$Form1 = GUICreate("Form1", 321, 239, 193, 125)
$Progress1 = GUICtrlCreateProgress(48, 48, 209, 33)
$Progress2 = GUICtrlCreateProgress(48, 96, 209, 41)
GUISetState(@SW_SHOW)

while $increment<1000
    if $count=1 then $x += 1
    if $x>99 then $count=2
    if $count=2 then $x -= 1
    if $x<1 then $count=1
    GUICtrlSetData($Progress1,$x)
    GUICtrlSetData($Progress2,$increment/10)
    sleep(50)
    $increment += 1
;need to increment second loop with your file operations
WEnd   

GUIDelete($form1)
msgbox(0,"","Done")

Share this post


Link to post
Share on other sites

can you increment the "current" bar during a file operation (filecopy) depending on how much of the operation has progressed or will it increment in a certain period of time? I'm still not sure how these work...

rasim's UDF of course :)

But for only 2 progresses may be, it's enough:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
Global $nDetail = 10 ; count of install steps

$Form1 = GUICreate("Form1", 400, 200)
GUICtrlCreateLabel('current: ', 10, 43, 60, 17)
$ProgressDetail = GUICtrlCreateProgress(75, 40, 315, 20, 0x01)
GUICtrlCreateLabel('sum: ', 10, 73, 60, 17)
$ProgressSum = GUICtrlCreateProgress(75, 70, 315, 20, 0x01)
GUISetState(@SW_SHOW)

_SetProgress()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SetProgress()
    Local $stepSum = Floor(100/$nDetail)
    Local $cntDetail, $cntSum = 0, $stepDetail, $cntFile
    For $i = 1 To $nDetail ; loop for progress-sum
        $cntDetail = 0
        $cntFile = 25
        $stepDetail = Floor(100/$cntFile)  ; step-width for install-steps, i.e. Floor(100/file count)
        For $j = 1 To $cntFile ; inner loop for installation, filecopy or whatever
            ; i.e. FileCopy
            Sleep(20)
            $cntDetail += $stepDetail
            GUICtrlSetData($ProgressDetail, $cntDetail)
        Next
        GUICtrlSetData($ProgressDetail, 100)
        Sleep(100)
        $cntSum += $stepSum
        GUICtrlSetData($ProgressSum, $cntSum)
    Next
    GUICtrlSetData($ProgressSum, 100)
EndFunc

Share this post


Link to post
Share on other sites

WoW! Thanks for all the responses. I went with GDIpProgress.au3 include that I found on the forum. I think it turned out pretty nicely.

Func InstallAndDisplayProgress($arraySize, $installFlag, $arrInstallKey)
    $loop = 0
    $ProgressFlag = 0
    $Gui = GUICreate("Installing Software", 350, 175, -1, -1, $GUI_SS_DEFAULT_GUI, $WS_EX_TOPMOST)
    $installMessage = GUICtrlCreateLabel("This may take a very long time!" ,$guiBorder *2, $guiBorder, 310, 25, $SS_CENTER+$SS_CENTERIMAGE)
    GUICtrlSetFont($installMessage, 9, 800, 0, "Arial")
    GUICtrlSetColor($installMessage, 0xFFFFFF)
    $installMessage2 = GUICtrlCreateLabel("Installation Progress" ,$guiBorder *2, $guiBorder*7.5, 310, 25, $SS_CENTER+$SS_CENTERIMAGE)
    GUICtrlSetFont($installMessage2, 9, 800, 0, "Arial")
    GUICtrlSetColor($installMessage2, 0xFFFFFF)
    $installMessage3 = GUICtrlCreateLabel($ProgressFlag & " of " & $numberOfSoftwareSelected & " programs installed so far." ,$guiBorder *2, $guiBorder*13, 310, 25, $SS_CENTER+$SS_CENTERIMAGE)
    GUICtrlSetFont($installMessage3, 9, 800, 0, "Arial")
    GUICtrlSetColor($installMessage3, 0xFFFFFF)

    $ProgressBar = _ProgressCreate($guiBorder, $guiBorder*10, 330, 30)
    _ProgressSetImages($ProgressBar, @ScriptDir & "\prgimgs\green.jpg", @ScriptDir & "\prgimgs\bg.jpg")
    $PMarquee = _ProgressCreate($guiBorder, $guiBorder*4, 330, 30)
    _ProgressSetImages($PMarquee, @ScriptDir & "\prgimgs\marquee.jpg", @ScriptDir & "\prgimgs\bg.jpg")
    _ProgressMarquee($PMarquee, 1, 0)
    GUISetCursor (0)
    GUISetFont(8, 800, 0, "Arial")
    GUISetBkColor(0x292929)
    GUISetState(@SW_SHOW)
    While $loop < $arraySize
        If $programs[$loop][$arrInstallKey] = $installFlag Then
            RunWait("Installers/" & $programs[$loop][$arrFileName])
            $ProgressFlag = $ProgressFlag + 1
            _ProgressSet($ProgressBar, Ceiling(($ProgressFlag/$numberOfSoftwareSelected) * 100))
            _ProgressSetText($ProgressBar, "Install " & Ceiling(($ProgressFlag/$numberOfSoftwareSelected)*100) & "%")
            If $ProgressFlag = $numberOfSoftwareSelected Then
                GUICtrlSetData($installMessage3, "Installation Complete!")
            Else
                GUICtrlSetData($installMessage3, $ProgressFlag & " of " & $numberOfSoftwareSelected & " programs installed so far.")
            EndIf
        EndIf
        $loop = $loop + 1
    WEnd
    Sleep(5000)
    _GDIPlus_Shutdown()
    GUIDelete($Gui)
EndFunc

post-44774-1232254412_thumb.jpg

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
Sign in to follow this  
Followers 0