Jump to content
Sign in to follow this  
PcExpert

Progress Bar

Recommended Posts

PcExpert

Hi all,

How do I create a progress bar that goes to for example 20% when a specified window opens or closes?

What I tried:

- Tried to do something with the GUICreateProgress

- tried to make my own

#include <GUIConstants.au3>

GUICreate("My GUI", 680, 100)  ; will create a dialog box that when displayed is centered
$ms = GUICtrlCreateProgress(10, 10, 600, 75)

GUICtrlSetData($ms, 20)
Sleep(4000)
GUICtrlSetData($ms, 40)
Sleep(4000)
GUICtrlSetData($ms, 60)
Sleep(4000)
GUICtrlSetData($ms, 80)
Sleep(4000)
GUICtrlSetData($ms, 100)
GUISetState (@SW_SHOW)       ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
 $msg = GUIGetMsg()
 
 If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

But this sets the progress immediately to 100% and it takes a long time to load. Whats wrong?

Edited by PcExpert

Share this post


Link to post
Share on other sites
Sokko

Take a look at the order of your code. You are creating the GUI, creating the progress bar, setting the progress bar to some values, showing the GUI, and going into the message loop. The reason your progress goes "immediately to 100%" is because you are not displaying the GUI (the @SW_SHOW line) until after you're done setting it to 100%.

Share this post


Link to post
Share on other sites
PcExpert

So I have to make a button that when clicked it starts?

Share this post


Link to post
Share on other sites
Sokko

You don't need a button. To repeat: Your problem is that you're not showing the window until after you've done the progress bar setting. Remember, any GUI you create is invisible until you show it with GUISetState. Here is your code again, but with the GUISetState line moved up so it happens before you set the progress bar.

#include <GUIConstants.au3>

GUICreate("My GUI", 680, 100)
$ms = GUICtrlCreateProgress(10, 10, 600, 75)

GUISetState(@SW_SHOW)

GUICtrlSetData($ms, 20)
Sleep(4000)
GUICtrlSetData($ms, 40)
Sleep(4000)
GUICtrlSetData($ms, 60)
Sleep(4000)
GUICtrlSetData($ms, 80)
Sleep(4000)
GUICtrlSetData($ms, 100)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Edited by Sokko

Share this post


Link to post
Share on other sites
PcExpert

Got it to work. Finally!

Share this post


Link to post
Share on other sites
PcExpert

One other question:

How to make the progress bar still visible even when an other program runs?

Share this post


Link to post
Share on other sites
SadBunny

One other question:

How to make the progress bar still visible even when an other program runs?

It has the 'always on top' by default, so it should actually be visible when you run other apps. You can disable it by using 2 as the 6th parameter.

I tried it to be sure, and it did stay on top (always visible) when I taskswitched while it was running...

Code used:

ProgressOn("test","test")
For $a = 1 To 100
    Sleep(100)
    ProgressSet($a)
Next
ProgressOff()

Roses are FF0000, violets are 0000FF... All my base are belong to you.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.