Jump to content

Progress Bar


Recommended Posts

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

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%.

Link to comment
Share on other sites

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

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.

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...