Jump to content

GuiGetMsg while doing task in background


Recommended Posts

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

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

Link to comment
Share on other sites

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

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

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

Not exactly what you wanted but thought I'd share it anyway:

#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

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