kevilay Posted December 28, 2018 Posted December 28, 2018 Hey guys, I have this script i am running that is pretty basic. I have at the end of each cycle a fairly large randomized delay, 5 - 15minutes. Right before this delay I show a message box, with the randomized value & a cycle count. What I would like to accomplish is to have a GUI (which I have never done) or a message box. That will show the count (done already) and the current value left in the timer. Just so I have an idea when it will cycle again. Its purely visual. This is just a small part of the script to give you an idea $y = $y+1 $z = Random(300000,900000) MsgBox(0,$z,$y,4) Sleep($z) Then my script continues below. Then jumps back to the top Thanks
Nine Posted December 28, 2018 Posted December 28, 2018 (edited) Problem with MsgBox is that user can always click ok button and leave early like in this code : #include <MsgBoxConstants.au3> #include <Timers.au3> ; your code here $time = $z/1000 $hGui = GUICreate("") $Timer = _Timer_SetTimer($hGui, 1000, "_UpdateMsgBox") MsgBox($MB_ICONWARNING, "Countdown", $time, $time) _Timer_KillTimer($hGui, $Timer) Func _UpdateMsgBox($hWnd, $Msg, $iIDTimer, $dwTime) Local $sText = ControlGetText("Countdown", "", "Static2") ControlSetText("Countdown", "", "Static2", $sText - 1) EndFunc ;==>_UpdateMsgBox One solution I would suggest is to use a progress bar like : #include <AutoItConstants.au3> ; Your code here $Time = $z/1000 ProgressOn("Progress Meter", "Increments every second", "0%", -1, -1, BitOR($DLG_NOTONTOP, $DLG_MOVEABLE)) For $i = 1 To $Time Sleep(1000) $t = int($i/$time*100) ProgressSet($t, $t & "%") Next ProgressOff() Edited December 28, 2018 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ModemJunki Posted December 28, 2018 Posted December 28, 2018 The problem with updating something like a label in a GUI will be flicker. If for example you update a label every second, the user will see the label flicker as it gets painted. I had that problem using a countdown timer in a GUI and I found the answer on the forums some years ago but I can't find my bookmark to the original post so I can't give credit to the author. I can, however, point to the post with a UDF for flicker-free labels (newer than my found solution) which I have not used yet: Else my original solution was to work around it with a control, maybe someone can make this example a little nicer, e.g. how to get rid of the box around the control... expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $setLabel = "" Opt("GUICloseOnESC", 0) ; prevent user from pressing escape key and accidentally cancelling the GUI #Region ### START Koda GUI section ### Global $Deploy_Dialogue = GUICreate("Oh bother", 601, 349, -1, -1, 0, $WS_EX_TOPMOST) GUISetFont(8, 400, 0, "MS Reference Sans Serif") Global $Header = GUICtrlCreateLabel("Universal Destructor", 0, 24, 597, 26, $SS_CENTER) GUICtrlSetFont(-1, 10, 400, 0, "MS Reference Sans Serif") Global $Warning = GUICtrlCreateLabel("", 0, 80, 599, 36, $SS_CENTER) GUICtrlSetFont(-1, 12, 800, 0, "MS Reference Sans Serif") Global $Static_text = GUICtrlCreateLabel("Intializing ....." & @CRLF & @CRLF & "Grab yer knickers, implosion starts soon!.", 40, 136, 516, 114) GUICtrlSetFont(-1, 10, 400, 0, "MS Reference Sans Serif") Global $OK_BTN = GUICtrlCreateButton("OK", 360, 272, 75, 25) GUICtrlSetState(-1, $GUI_HIDE) Global $CANCEL_BUTTON = GUICtrlCreateButton("Cancel", 456, 272, 75, 25, $BS_DEFPUSHBUTTON) GUICtrlSetState(-1, $GUI_HIDE) Global $Counter = GUICtrlCreateInput("", 32, 272, 25, 24, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlSetState(-1, $GUI_HIDE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Warning, "!!!!!!!!!!!!!!! A C H T U N G !!!!!!!!!!!!!!!!") GUICtrlSetState($Counter, $GUI_SHOW) GUICtrlSetState($OK_BTN, $GUI_SHOW) GUICtrlSetState($CANCEL_BUTTON, $GUI_SHOW) GUICtrlSetState($CANCEL_BUTTON, $GUI_FOCUS) $Timer = TimerInit() ; initialize timer $wait = 1000 * 15 ; 15 second wait for the user to stop the implosion While TimerDiff($Timer) < $wait $nMsg = GUIGetMsg() $seconds = TimerDiff($Timer) / 1000 $diff = $seconds - ($wait / 1000) $minutes = Int($diff / 60) $secondsRem = $diff - ($minutes * 60) $secondsRem = $secondsRem * -1 $time = StringFormat("%02d", $secondsRem) If $time < 5 And $setLabel = "" Then $setLabel = 1 GUICtrlSetData($Warning, "!!!!!!!!!!!!!!! O h , d e a r !!!!!!!!!!!!!!!!") GUICtrlSetData($Static_text, "In 5 seconds the timer will end and the universe will implode." & @CRLF & @CRLF & "To exit you can still click Cancel..") EndIf GUICtrlSetData($Counter, $time) Switch $nMsg Case $GUI_EVENT_CLOSE ; the GUI crashed (should never happen) or more likeley you allowed the user to use ESC to close the GUI ; do something here if the GUI crashed; probably just follow the dolphins Case $CANCEL_BUTTON ; do something here, the user canceled GUISetState(@SW_HIDE, $Deploy_Dialogue) ; hide the GUI MsgBox(48, "Oopsies!", "You cannot stop entropy.") Exit Case $OK_BTN ; do something here, the user clicked OK GUISetState(@SW_HIDE, $Deploy_Dialogue) ; hide the GUI MsgBox(4096, "Hooray!", "Entropy is accelerated!") Exit EndSwitch WEnd ; after 15 seconds the GUI will close and your stuff starts GUISetState(@SW_HIDE, $Deploy_Dialogue) ; hide the GUI MsgBox(4096, "Whee!", "Entropy wins the day!", 15) exit Have fun! Always carry a towel.
kevilay Posted December 28, 2018 Author Posted December 28, 2018 The progress bar looks like a great idea
kevilay Posted December 28, 2018 Author Posted December 28, 2018 1 hour ago, Nine said: Problem with MsgBox is that user can always click ok button and leave early like in this code : #include <MsgBoxConstants.au3> #include <Timers.au3> ; your code here $time = $z/1000 $hGui = GUICreate("") $Timer = _Timer_SetTimer($hGui, 1000, "_UpdateMsgBox") MsgBox($MB_ICONWARNING, "Countdown", $time, $time) _Timer_KillTimer($hGui, $Timer) Func _UpdateMsgBox($hWnd, $Msg, $iIDTimer, $dwTime) Local $sText = ControlGetText("Countdown", "", "Static2") ControlSetText("Countdown", "", "Static2", $sText - 1) EndFunc ;==>_UpdateMsgBox One solution I would suggest is to use a progress bar like : #include <AutoItConstants.au3> ; Your code here $Time = $z/1000 ProgressOn("Progress Meter", "Increments every second", "0%", -1, -1, BitOR($DLG_NOTONTOP, $DLG_MOVEABLE)) For $i = 1 To $Time Sleep(1000) $t = int($i/$time*100) ProgressSet($t, $t & "%") Next ProgressOff() Progress bar worked perfect. Great Advice Thank you!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now