Jump to content

Update progress bar value in active GUI


Go to solution Solved by ddxfish,

Recommended Posts

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

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Solution

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

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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