Baruch Posted May 9, 2017 Share Posted May 9, 2017 Local $Timer = TimerInit() Local $Delay = 30 Local $TimeS = $Delay - Int ((TimerDiff ($Timer)) / 1000) Local $While = 1 $hGUI = GUICreate("Attendo...", 400, 100) GUISetState(@SW_SHOW, $hGUI) Local $Abort = GUICtrlCreateButton("ABORT",170,60) GUISetIcon ("shell32.dll", 51) Local $Label = GUICtrlCreateLabel ("Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere", 110, 20) While $While = 1 Switch GUIGetMsg() Case $Abort Exit EndSwitch If $TimeS > 0 then GUICtrlSetData ($Label,"Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere") $TimeS = $Delay - Int ((TimerDiff ($Timer)) / 1000) Else $while = 0 EndIf Wend This is My code, i would like to know what method i could use to pause my script after the GuiCtrlSetData for a while without broking the ABORT button ($Abort). I made it working by deleting the Sleep command after the GuiCtrlSetData, but it is annoying to have the Label refreshed every millisecond! Hope you could help me figure this out! Thanks in Advance Link to comment Share on other sites More sharing options...
MilesAhead Posted May 9, 2017 Share Posted May 9, 2017 I am not totally sure what you want the result to be but the changes I made reduced the number of label updates. Local $Timer = TimerInit() Local $Delay = 30 Local $TimeS = $Delay - Int((TimerDiff($Timer)) / 1000) Local $While = 1 $hGUI = GUICreate("Attendo...", 400, 100) GUISetState(@SW_SHOW, $hGUI) Local $Abort = GUICtrlCreateButton("ABORT", 170, 60) GUISetIcon("shell32.dll", 51) Local $Label = GUICtrlCreateLabel("Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere", 110, 20) While $While = 1 Switch GUIGetMsg() Case $Abort Exit EndSwitch If Not Mod($TimeS, 2) Then GUICtrlSetData($Label, "Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere") $TimeS = $Delay - Int((TimerDiff($Timer)) / 1000) EndIf WEnd My Freeware Page Link to comment Share on other sites More sharing options...
Baruch Posted May 11, 2017 Author Share Posted May 11, 2017 On 9/5/2017 at 6:30 PM, MilesAhead said: I am not totally sure what you want the result to be but the changes I made reduced the number of label updates. Local $Timer = TimerInit() Local $Delay = 30 Local $TimeS = $Delay - Int((TimerDiff($Timer)) / 1000) Local $While = 1 $hGUI = GUICreate("Attendo...", 400, 100) GUISetState(@SW_SHOW, $hGUI) Local $Abort = GUICtrlCreateButton("ABORT", 170, 60) GUISetIcon("shell32.dll", 51) Local $Label = GUICtrlCreateLabel("Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere", 110, 20) While $While = 1 Switch GUIGetMsg() Case $Abort Exit EndSwitch If Not Mod($TimeS, 2) Then GUICtrlSetData($Label, "Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere") $TimeS = $Delay - Int((TimerDiff($Timer)) / 1000) EndIf WEnd Sorry but with your fix it doesn't refresh anymore! Link to comment Share on other sites More sharing options...
Floops Posted May 11, 2017 Share Posted May 11, 2017 How about this? Local $Timer = TimerInit() Local $Delay = 30 Local $TimeS = $Delay - Int ((TimerDiff ($Timer)) / 1000) Local $While = 1 $hGUI = GUICreate("Attendo...", 400, 100) GUISetState(@SW_SHOW, $hGUI) Local $Abort = GUICtrlCreateButton("ABORT",170,60) GUISetIcon ("shell32.dll", 51) Local $Label = GUICtrlCreateLabel ("Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere", 110, 20) While $While = 1 Switch GUIGetMsg() Case $Abort Exit EndSwitch If $TimeS > 0 then $TimeS_NEW = $Delay - Int ((TimerDiff ($Timer)) / 1000) If $TimeS_NEW < $TimeS Then GUICtrlSetData ($Label,"Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere") $TimeS = $TimeS_NEW EndIf Else $while = 0 EndIf Wend Link to comment Share on other sites More sharing options...
Baruch Posted May 11, 2017 Author Share Posted May 11, 2017 For future references, i've fixed this way Func Wait() Local $Timer = TimerInit() Local $Delay = 30 Local $TimeS = $Delay - Int ((TimerDiff ($Timer)) / 1000) Local $TimeM = $Delay - Round((TimerDiff ($Timer) / 1000), 1) Local $While = 1 $hGUI = GUICreate("Attendo...", 400, 100) GUISetState(@SW_SHOW, $hGUI) Local $Abort = GUICtrlCreateButton("ABORT",170,60) GUISetIcon ("shell32.dll", 51) Local $Label = GUICtrlCreateLabel ("Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere", 110, 20) While $While = 1 Switch GUIGetMsg() Case $Abort, $GUI_EVENT_CLOSE MsgBox ($MB_SYSTEMMODAL,"Shutdown","Shutting Down...",2) Exit EndSwitch If IsInt ($TimeM) then GUICtrlSetData ($Label,"Attendo " & $TimeS & " secondi" & @CRLF & "premere ABORT se si vuole interrompere") $TimeM = $Delay - Round((TimerDiff ($Timer) / 1000), 1) $TimeS = $Delay - Int ((TimerDiff ($Timer)) / 1000) ElseIf $TimeS <= 0 Then $while = 0 Else $TimeM = $Delay - Round((TimerDiff ($Timer) / 1000), 1) $TimeS = $Delay - Int ((TimerDiff ($Timer)) / 1000) EndIf Wend EndFunc By the way also @Floops solution works! Thank you Link to comment Share on other sites More sharing options...
Subz Posted May 11, 2017 Share Posted May 11, 2017 Not exactly what you wanted but thought I'd share it anyway: expandcollapse popup#include <GUIConstants.au3> #include <MsgBoxConstants.au3> Global $idAbortButton, $idLabel, $bPause = False, $iPause Global $hTimer = TimerInit() Global $iDelay = 30 Global $iTimer = 30 $hGUI = GUICreate("Attendo...", 400, 100) GUISetIcon ("shell32.dll", 51) $idAbortButton = GUICtrlCreateButton("ABORT",100,60, 100, 30) $idPause = GUICtrlCreateButton("PAUSE",200,60, 100, 30) $idLabel = GUICtrlCreateLabel ("Attendo " & $iTimer & " secondi" & @CRLF & "premere ABORT se si vuole interrompere", 110, 20) GUISetState() AdlibRegister("_CountDown") While 1 Switch GUIGetMsg() Case $idAbortButton, $GUI_EVENT_CLOSE MsgBox ($MB_SYSTEMMODAL,"Shutdown","Shutting Down...",2) Exit Case $idPause If $bPause = True Then $bPause = False $iDelay = $iTimer $hTimer = TimerInit() ElseIf $bPause = False Then $bPause = True EndIf EndSwitch Wend Func _CountDown() If $bPause = True Then Return If $iTimer > 0 then GUICtrlSetData ($idLabel,"Attendo " & $iTimer & " secondi" & @CRLF & "premere ABORT se si vuole interrompere") $iTimer = $iDelay - Int ((TimerDiff ($hTimer)) / 1000) EndIf EndFunc Link to comment Share on other sites More sharing options...
MilesAhead Posted May 11, 2017 Share Posted May 11, 2017 7 hours ago, Baruch said: Sorry but with your fix it doesn't refresh anymore! It does on my laptop. Likely the number to use in the modulus function is dependent on the speed of the machine. A tooltip may work better than a msgbox though. My Freeware Page Link to comment Share on other sites More sharing options...
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