Jump to content

Progress Bar


Monkey
 Share

Recommended Posts

Hi, I just downloaded autoit v3, and find it awesome. however, im still new to it, and was thinking of making a progress bar, but i couldnt find a way to make one.

I need a progress bar that i control the percentage.

or maybe anyone have a link to a guide in making progress bar. please tell me...thanks!

Link to comment
Share on other sites

Hi and welcome to the forum!

When you are having any problem you should start by checking the helpfile (open it by pressing F1 when you ahve a script loaded in SciTE) and then search on the forum. You would have found a way to do it then, but since I am here anyway.... Check GUICtrlCreateProgress() if you want it in your gui or ProgressOn() if you only need a "status window" (hard to explain, just check the helpfile)

Link to comment
Share on other sites

ProgressOn ( "title", "maintext" [, "subtext" [, x pos [, y pos [, opt]]]] )

ProgressOn("Progress Meter", "Increments every second", "0 percent")

For $i = 10 to 100 step 10

sleep(1000)

ProgressSet( $i, $i & " percent")

Next

ProgressSet(100 , "Done", "Complete")

sleep(500)

ProgressOff()

To find it search for "progress" in the help file. Really easy. There are other more complicated means of producing a progress bar but this should suffice.

Copy / Pasted right out of the help file.

Link to comment
Share on other sites

Thanks guys for the fast reply!

I have checked the help file, also tried the GUICtrlCreateProgress() etc, but i cant seem to make them work, the window wont appear.

anyways, im reading the help file now, so ill try again making the progress bar.

firstly, ill try jebus495's quotes...hehehe thanks man!

Link to comment
Share on other sites

Ok, i got my progress bar working now. thanks!

Now, im working on inserting button(s) in the progress bar dialog box...just below the progress bar animation....

Hope anyone can guide me to making one...im still reading help file hehehe

Link to comment
Share on other sites

Thanks guys for the fast reply!

I have checked the help file, also tried the GUICtrlCreateProgress() etc, but i cant seem to make them work, the window wont appear.

anyways, im reading the help file now, so ill try again making the progress bar.

firstly, ill try jebus495's quotes...hehehe thanks man!

Creating a GUI according to the helpfile:

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

Opt('MustDeclareVars', 1)

Example1()
Example2()

; example 1
Func Example1()
    Local $msg

    GUICreate("My GUI"); will create a dialog box that when displayed is centered
    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
    GUIDelete()
EndFunc  ;==>Example1

; example 2
Func Example2()
    Local $gui, $background, $pic, $basti_stay, $msg
    Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\logo4.gif"
    
    $gui = GUICreate("Background", 400, 100)
   ; background picture
    $background = GUICtrlCreatePic(@SystemDir & "\oobe\images\mslogo.jpg", 0, 0, 400, 100)
    GUISetState(@SW_SHOW)

   ; transparent MDI child window
    $pic = GUICreate("", 169, 68, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $gui)
   ; transparent pic
    $basti_stay = GUICtrlCreatePic($sFile, 0, 0, 169, 68)
    GUISetState(@SW_SHOW)

    Do
        $msg = GUIGetMsg()

    Until $msg = $GUI_EVENT_CLOSE
EndFunc  ;==>Example2
Link to comment
Share on other sites

Ok, i got my progress bar working now. thanks!

Now, im working on inserting button(s) in the progress bar dialog box...just below the progress bar animation....

Hope anyone can guide me to making one...im still reading help file hehehe

Creating a button according to the helpfile:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $Button_1, $Button_2, $msg
    GUICreate("My GUI Button"); will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("Run Notepad", 10, 30, 100)
    $Button_2 = GUICtrlCreateButton("Button Test", 0, -1)

    GUISetState()    ; will display an  dialog box with 2 button

   ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                Run('Notepad.exe')   ; Will Run/Open Notepad
            Case $msg = $Button_2
                MsgBox(0, 'Testing', 'Button 2 was pressed')   ; Will demonstrate Button 2 being pressed
        EndSelect
    WEnd
EndFunc  ;==>Example
Link to comment
Share on other sites

Creating a button according to the helpfile:

#include <GUIConstantsEx.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $Button_1, $Button_2, $msg
    GUICreate("My GUI Button"); will create a dialog box that when displayed is centered

    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("Run Notepad", 10, 30, 100)
    $Button_2 = GUICtrlCreateButton("Button Test", 0, -1)

    GUISetState()   ; will display an  dialog box with 2 button

  ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                Run('Notepad.exe')  ; Will Run/Open Notepad
            Case $msg = $Button_2
                MsgBox(0, 'Testing', 'Button 2 was pressed')  ; Will demonstrate Button 2 being pressed
        EndSelect
    WEnd
EndFunc ;==>Example

Yes, I read about that, but my problem is, in that codes it creates its own dialog box("My GUI Button"), what i want to do is to place button(s) within the progress bar dialog box.

I hope i made it clearer.

Link to comment
Share on other sites

Yes, I read about that, but my problem is, in that codes it creates its own dialog box("My GUI Button"), what i want to do is to place button(s) within the progress bar dialog box.

I hope i made it clearer.

Try this:

#include <GuiStatusBar.au3>
#include <GuiConstantsEx.au3>

; GUI
GUICreate("Windows Update Cleanup", 500, 65)
$sFile = "C:\Documents and Settings\Lasse\Dokumenter\Auto-it Scripts\icon.ico"
GUISetIcon($sFile)

; PROGRESS
$label = GUICtrlCreateLabel("Progress...", 10, 40, 480, 20, 1)
$progressbar = GUICtrlCreateProgress(50, 10, 400, 20)
GUICtrlSetData($progressbar, $progress)
GUISetState(@SW_SHOW)

Now you have a GUI with a progressbar and a label. You should be able to create buttons in that GUI as you please.

Link to comment
Share on other sites

Try this:

#include <GuiStatusBar.au3>
#include <GuiConstantsEx.au3>

; GUI
GUICreate("Windows Update Cleanup", 500, 65)
$sFile = "C:\Documents and Settings\Lasse\Dokumenter\Auto-it Scripts\icon.ico"
GUISetIcon($sFile)

; PROGRESS
$label = GUICtrlCreateLabel("Progress...", 10, 40, 480, 20, 1)
$progressbar = GUICtrlCreateProgress(50, 10, 400, 20)
GUICtrlSetData($progressbar, $progress)
GUISetState(@SW_SHOW)

Now you have a GUI with a progressbar and a label. You should be able to create buttons in that GUI as you please.

And by the way (I know your going to be asking this in a minute) - Here's a link to my first question in here ever :)

http://www.autoitscript.com/forum/index.ph...&hl=Edifice

Edit: And Remember to run a while 1 loop to keep the GUI showing. Most examples from the help-file does this.

:) I cant make the gui stay, and i dunno how to make the bar animate. dang sorry for being so newbie-ish...

hope you can guide me through what you want me to do ^_^

Link to comment
Share on other sites

Sorry if I were a little quick to post some crappy example for you.

Here's a little test window for you to play around in :)

#include <GuiStatusBar.au3>
#include <GuiConstantsEx.au3>

Dim $progress = 0

; GUI
GUICreate("Progress and buttons", 500, 100)

; PROGRESS
$label = GUICtrlCreateLabel("Progress...", 300, 40, 100, 20, 1)
$progressbar = GUICtrlCreateProgress(50, 10, 400, 20)
GUICtrlSetData($progressbar, $progress)
GUISetState(@SW_SHOW)

$Button_1 = GUICtrlCreateButton("Minus", 10, 50, 100, 30)
$Button_2 = GUICtrlCreateButton("Plus", 140,50, 100, 30)

    While 1
        GUICtrlSetData($progressbar, $progress)
        GUICtrlSetData($label, "Progress...:" & $progress)
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                If $progress > 1 Then
                    $progress  =  $progress - 10
                Else
                    $progress = 100
                EndIf
            Case $msg = $Button_2
                If $progress < 99 Then
                    $progress  =  $progress + 10
                Else
                    $progress = 0
                EndIf
        EndSelect
    WEnd
Edited by Edifice
Link to comment
Share on other sites

Sorry if I were a little quick to post some crappy example for you.

Here's a little test window for you to play around in :)

#include <GuiStatusBar.au3>
#include <GuiConstantsEx.au3>

Dim $progress = 0

; GUI
GUICreate("Progress and buttons", 500, 100)

; PROGRESS
$label = GUICtrlCreateLabel("Progress...", 300, 40, 100, 20, 1)
$progressbar = GUICtrlCreateProgress(50, 10, 400, 20)
GUICtrlSetData($progressbar, $progress)
GUISetState(@SW_SHOW)

$Button_1 = GUICtrlCreateButton("Minus", 10, 50, 100, 30)
$Button_2 = GUICtrlCreateButton("Plus", 140,50, 100, 30)

    While 1
        GUICtrlSetData($progressbar, $progress)
        GUICtrlSetData($label, "Progress...:" & $progress)
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                If $progress > 1 Then
                    $progress  =  $progress - 10
                Else
                    $progress = 100
                EndIf
            Case $msg = $Button_2
                If $progress < 99 Then
                    $progress  =  $progress + 10
                Else
                    $progress = 0
                EndIf
        EndSelect
    WEnd
WOW! Ill experiment with these codes.

By the way, If you have questions about it just ask away - And I don't mind the newbie-ish, not that long ago I was asking the same questions :)

Sure! Thanks for the consideration lol...
Link to comment
Share on other sites

slightly modded to stop the flickering.

While 1
         if GUICtrlRead($progressbar)<>$progress Then
        GUICtrlSetData($progressbar, $progress)
        GUICtrlSetData($label, "Progress...:" & $progress)
        EndIf
        $msg = GUIGetMsg()
..............REST OF CODE
..............
Link to comment
Share on other sites

  • 3 weeks later...

Hallo,

I allowed me to adapt your script according to my needs. It works fine, but curiously my button looks like to be inactive = i can not push it :P . I think this behaviour has to do with my Sleep(1000) command. Could somebody help me to fix this bug?

Thanks a lot

Joe

#include <GuiStatusBar.au3>
#include <GuiConstantsEx.au3>

Dim $progress = 100
$sec = 30

; GUI
GUICreate("System auto shut down sequence", 400, 130)

; PROGRESS WITH LABEL
$label = GUICtrlCreateLabel("System will shut down in " & $sec & " seconds", 100, 50, 200, 30, 1)
$progressbar = GUICtrlCreateProgress(50, 20, 300, 20)
GUICtrlSetData($progressbar, $progress)
GUISetState(@SW_SHOW)

;BUTTON
$stopButton = GUICtrlCreateButton("Stop countdown", 100, 80, 200, 30)
GUICtrlSetBkColor($stopButton, 0xff0000) 

;COUNTDOWN
for $i=$sec to 1 step -1
        if GUICtrlRead($progressbar)<>$progress Then
            GUICtrlSetData($progressbar, $progress)
            GUICtrlSetData($label, "System will shut down in " & $i & " seconds")
        EndIf
        
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $stopButton
                ExitLoop
        EndSelect
        
        If $progress == 0 Then
        ; shut down the computer
            ExitLoop 
        Else
            Sleep(1000)
            $progress = $progress - 100/$sec
        EndIf
Next
Link to comment
Share on other sites

Hallo,

i found solution. If somebody has better idea i would like to compare it.

Thanks Joe

#include <GuiStatusBar.au3>
#include <GuiConstantsEx.au3>

Dim $progress = 100
$sec = 30

; GUI
GUICreate("System auto shut down sequence", 400, 130)

; PROGRESS WITH LABEL
$label = GUICtrlCreateLabel("System will shut down in " & $sec & " seconds", 100, 50, 200, 30, 1)
$progressbar = GUICtrlCreateProgress(50, 20, 300, 20)
GUICtrlSetData($progressbar, $progress)
GUISetState(@SW_SHOW)

;BUTTON
$stopButton = GUICtrlCreateButton("Stop countdown", 100, 80, 200, 30)
GUICtrlSetBkColor($stopButton, 0xff0000) 

;COUNTDOWN
;for $i=$mSec to 0 step -1
$secRem = $sec
$begin = TimerInit()
while 1
    if GUICtrlRead($progressbar)<>$progress Then
        GUICtrlSetData($progressbar, $progress)
        GUICtrlSetData($label, "System will shut down in " & $secRem & " seconds")
    EndIf
        
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $stopButton
            ExitLoop
    EndSelect
        
        If $secRem == 0 Then
        ; shut down the computer
            ExitLoop 
        Elseif TimerDiff($begin) >= 1000 Then
            $progress = $progress - 100/$sec
            $secRem = $secRem - 1
            $begin = TimerInit()
        EndIf
WEnd
Link to comment
Share on other sites

  • 2 weeks later...

Actually, I found a solution that is just a tiny bit better (not much).

Do
            $msg = GUIGetMsg()
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    progend()
                Case $msg = $STOP
                    progend()
            EndSelect
            $counter = $counter +25
            Sleep(1)
        Until $counter > 1000
        $counter = 0

If you insert this into the while-loop that runs the GUI it will make sure that the exe spends most of it's time in the select that checks for GUI_EVENT_CLOSE. I can't figure out why the counter has to be +25 and not 1, but I timed it and it seems to be very accurate compared to my chronograph, although that could just be on my computer.

I made a program with the same functionality that yours have, accept it also auto-logs back into the user if it has no password. Note that it will forever auto-login if you do not open and then close the program once afterwards.

It looks like this:

CODE

#include <GuiStatusBar.au3>

#include <GuiConstantsEx.au3>

#include <WindowsConstants.au3>

Dim $progress = 0

Dim $hours = 00

Dim $minutes = 04

Dim $seconds = 00

$Userid = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName")

$Psw = ""

GUIRegisterMsg($WM_CLOSE, "progend")

SetAutoLogon("Off", "")

; GUI

GUICreate("Startup / Shutdown test", 500, 150)

$progressbar = GUICtrlCreateProgress(25, 10, 450, 70)

$label = GUICtrlCreateLabel("System Shutdown in: "& $hours & " : " & $minutes & " : " & $seconds, 10, 90, 480, 20, 1)

$STOP = GUICtrlCreateButton("Stop", 200, 115, 100, 25)

GUISetState(@SW_SHOW)

runprogram()

Func runprogram()

local $counter = 0

While 1

Do

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

progend()

Case $msg = $STOP

progend()

EndSelect

$counter = $counter +25

Sleep(1)

Until $counter > 1000

$counter = 0

$progress = $progress + 100/(4*60)

if GUICtrlRead($progressbar)<>$progress Then

GuiCtrlSetdata($progressbar, $progress)

GuiCtrlSetdata($label,"System Shutdown in: "& $hours & " : " & $minutes & " : " & $seconds)

EndIf

If $seconds < 1 Then

If $minutes < 1 Then

If $hours < 1 Then

SetAutoLogon("On", "step1")

MsgBox(0, "Test", "System should now reboot")

;Shutdown(6) ; Forces a reboot of the system

Exit

Else

$hours = $hours - 1

$minutes = 59

$seconds = 59

EndIf

Else

$minutes = $minutes - 1

$seconds = 59

EndIf

Else

$seconds = $seconds - 1

EndIf

WEnd

EndFunc

Func progend()

SetAutoLogon("Off", "")

Exit

EndFunc

Func SetAutoLogon($sw, $step)

Local $s1, $s2, $s3, $s4

If $sw = "On" Then

; set the registry to start this program again after reboot

; Read current settings

$s1 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "AutoAdminLogon")

$s2 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultDomainName")

$s3 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName")

$s4 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultPassword")

;Save current settings

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_AutoAdminLogon", "REG_SZ", $s1)

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultDomainName", "REG_SZ", $s2)

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultUserName", "REG_SZ", $s3)

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultPassword", "REG_SZ", $s4)

;Set New Settings

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "AutoItInstaller", "REG_SZ", @ScriptFullPath & " " & $step)

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "AutoAdminLogon", "REG_SZ", "1")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultDomainName", "REG_SZ", EnvGet("LOGONSERVER"))

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName", "REG_SZ", $Userid)

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultPassword", "REG_SZ", $Psw)

EndIf

;

If $sw = "Off" Then

; Read previous settings and reset

$s1 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_AutoAdminLogon")

If Not @error Then

RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_AutoAdminLogon")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "AutoAdminLogon", "REG_SZ", $s1)

EndIf

$s2 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultDomainName")

If Not @error Then

RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultDomainName")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultDomainName", "REG_SZ",$s2)

EndIf

$s3 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultUserName")

If Not @error Then

RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultUserName")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultUserName", "REG_SZ", $s3)

EndIf

$s4 = RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultPassword")

If Not @error Then

RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "S_DefaultPassword")

RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\", "DefaultPassword", "REG_SZ", $s4)

EndIf

; Remove/Reset the registrykey to start this program again after reboot

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RUN", "AutoItInstaller")

EndIf

EndFunc ;==>SetAutoLogon

Edited by Edifice
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...