Sign in to follow this  
Followers 0
ddxfish

Update progress bar value in active GUI

6 posts in this topic

#1 ·  Posted (edited)

I have a GUI designed with a status message, and a progress bar. I want to make a function that changes the progress bar value on this active GUI window (ProgressOn is not a versatile enough solution).

Here are the 2 functions I have so far, the first opens the GUI and the second is supposed to change the progress bar value by inputting the new percent, but does not work. I was hoping to call my function setStatusGui(50) to set the percent to 50.

Any help would be greatly appreciated!

EDIT: updated code to run as I see it

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

Global $currentStatus = "Not started yet"
Global $currentStatusHeader = "Long Script - Paused"
Global $currentProgress = 0

Func openStatusGUI()
    #Region ### START Koda GUI section ### Form=
    Global $simpleForm = GUICreate("Script Status", 504, 247, 192, 124)
    Global $simpleTitle = GUICtrlCreateLabel($currentStatusHeader, 11, 8, 481, 49, $SS_CENTER)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    Global $simpleStatusmsg = GUICtrlCreateLabel($currentStatus, 23, 88, 456, 49, $SS_CENTER)
    Global $simpleProgress = GUICtrlCreateProgress(24, 184, 454, 49, $WS_BORDER)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>openStatusGUI

Func setStatusGui($newprogress)
    GUICtrlSetData($simpleProgress, $newprogress)
EndFunc   ;==>setStatusGui


;Execution
openStatusGUI()
Sleep(1000)
setStatusGui(66)
Edited by Jos

Share this post


Link to post
Share on other sites



Welcome, please post a script that can run and shows what you are trying to do as the setStatusGui() will nicely update the progressbar.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I edited the original code, sorry about that. I see the GUI load, and expect for the progress bar to change to 66% after a 1000 msec sleep, but it stays at 0.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Updated your code to be in a codebox for easier reading. :)

Your Gui is locked into your Message loop so never reaches the setStatusGui() line.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Jos, Thanks so much for the help. I made a bonehead mistake there. Here is the working code.

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

Global $currentGuiStatus = 0
Global $currentStatus = "Not started yet"
Global $currentStatusHeader = "Long Script - Paused"
Global $currentProgress = 0

Func openStatusGUI()
    $currentGuiStatus = 1
    #Region ### START Koda GUI section ### Form=
    Global $simpleForm = GUICreate("Script Status", 504, 247, 192, 124)
    Global $simpleTitle = GUICtrlCreateLabel($currentStatusHeader, 11, 8, 481, 49, $SS_CENTER)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    Global $simpleStatusmsg = GUICtrlCreateLabel($currentStatus, 23, 88, 456, 49, $SS_CENTER)
    Global $simpleProgress = GUICtrlCreateProgress(24, 184, 454, 49, $WS_BORDER)
    GUISetState(@SW_SHOWNORMAL)
    #EndRegion ### END Koda GUI section ###

EndFunc   ;==>openStatusGUI

Func setStatusGui($newprogress)
    GUICtrlSetData($simpleProgress, $newprogress)
EndFunc   ;==>setStatusGui


;Execution
openStatusGUI()
Sleep(1000)
setStatusGui(66)
Sleep(1000)
Edited by ddxfish

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You will have to create some sort of loop to keep the program active, but that isn't an issue really.

Just use the GUIOnEventMode mode to trigger any actions from the GUIControls and use an AdlibRegister() to activate another function at a defined interval.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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