Jump to content

Progressbar - (Moved)


jan48
 Share

Recommended Posts

#include <GUIConstantsEx.au3>

Global $pb, $tw,$bc,$pl,$p=0,$perc=0

$tw = GUICreate("Test Progressbar",250,110)
$pb=GUICtrlCreateProgress ( 20, 10 ,210,20)
$pl=GUICtrlCreateLabel ( "", 20, 40 ,50,25)
$bc = GUICtrlCreateButton("Close", 170, 80, 70, 25)
GUISetState(@SW_SHOW, $tw)

; Loop until Close button is pushed.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $bc
            ExitLoop
    EndSwitch
    $p+=7
    $perc=round($p/1000,3)
    if $perc>=100 then ExitLoop
    GUICtrlSetData ( $pl, $perc)
    GUICtrlSetData ( $pb, $perc)
WEnd

; Delete the GUI and all controls.
GUIDelete($tw)

The standard progressbar will only update on percentage integers, not on a float.

I run Autoit 3.3.14.5 64 bit on Windows 10 Pro.

Edited by jan48
Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the AutoIt Example Scripts forum very clearly states:

Quote

Share your cool AutoIt scripts, UDFs and applications with others.


Do not post general support questions here, instead use the AutoIt Help and Support forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ok I see now what you meant.  It is even more obvious using larger bar and adding a sleep at the end of the loop :

...
$tw = GUICreate("Test Progressbar", 500, 110)
$pb = GUICtrlCreateProgress(20, 10, 460, 20)
....
    Sleep(50)
WEnd

The progress bar only updates when it hits next integer value.  In between integers it does not.

Not sure why it was implemented that way...

Edited by Nine
Link to comment
Share on other sites

@Nine : some thoughts about this.
I added a counter in OP's script, the While...Wend is looped 14286 times.
So I tried to simulate a progress bar with a colored label having a 500 pixels width, which means that 1 pixel has to be shown every 28.572 times (14286 / 500 = 28.572)

Here are 2 scripts quickly done (constants need to be reworked etc...),  they may be useful to simulate an updated progress bar when percentages are needed :

* 1st one, the basic idea :

#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>

Local $hGUI = GUICreate("Test Progressbar", 520, 200)

Local $idLabel = GUICtrlCreateLabel ("", 10, 10, 0, 20)
Local $hLabel = GUICtrlGetHandle($idLabel)
GUICtrlSetBkColor($idLabel, $COLOR_RED)

Local $pl = GUICtrlCreateLabel("", 20, 40, 50, 20)

GUISetState()

Local $iWidth = 0

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    $iWidth += 1
    If $iWidth > 500 Then ExitLoop
    GUICtrlSetData($pl, $iWidth & " / 500")

    WinMove($hLabel, "", 10, 10, $iWidth)
    Sleep(50)
WEnd

GUIDelete()

* 2nd script, more adapted to OP :

#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Local $p=0, $perc=0

Local $hGUI = GUICreate("Test Progressbar", 520, 200)

GUICtrlCreateLabel("", 9, 9, 500, 22, $SS_SUNKEN)
GUICtrlSetState(-1, $GUI_DISABLE)

Local $idLabel = GUICtrlCreateLabel ("", 10, 10, 0, 20)
Local $hLabel = GUICtrlGetHandle($idLabel)
GUICtrlSetBkColor($idLabel, $COLOR_RED)

Local $pl = GUICtrlCreateLabel("", 20, 40, 50, 20)

GUISetState()

Local $iWidth = 0

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    $p+=7
    $perc=round($p/1000,3)
    If $perc >= 100 then ExitLoop
    GUICtrlSetData($pl, $perc)

    If Mod($p, 28.572) < 1 Then
        $iWidth += 1
        WinMove($hLabel, "", 10, 10, $iWidth)
    EndIf
WEnd

GUIDelete()

 

Edited by pixelsearch
replaced variable name $iInc with $iWidth
Link to comment
Share on other sites

Thanks for the working example of a progressbar.
I am sure  that I used a working progessbar in an earlier project before some time ago.
It was exactly as in my example and it was running fine.

Maybe this was an earlier version of Windows and/or an earlier version of Autoit.
So my question is simple: did the behaviour of a progressbar change since then?

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