Countdown und Progressbar

  • Hallo,

    wie schaffe ich es das sich die Progressbar füllt und die Zeit runterläuft ?

    Spoiler anzeigen
    [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    $fill = 15000

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("My GUI")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    $ID_1 = GUICtrlCreateButton("Countdown", 10, 20, 100)
    $ID_2 = GUICtrlCreateButton("Progress", 10, 50, 100)
    $progress = GUICtrlCreateProgress(60, 0, 200, 20)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $ID_1
    _sleep(30000)
    Case $ID_2
    _fill()
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _sleep($time)
    $tstart = TimerInit()
    $stime = $time
    Do
    GUICtrlCreateLabel("Zeit : " & $stime / 1000 & "sec", 0, 0)
    Sleep(1000)
    $stime -= 1000
    Until TimerDiff($tstart) >= $time
    EndFunc ;==>_sleep

    [/autoit] [autoit][/autoit] [autoit]

    Func _fill()
    For $x = 0 To 15000
    $test = $x ^ 2
    GUICtrlSetData($progress, $x * (100 / $fill))
    Next
    EndFunc ;==>_fill

    [/autoit]

    Das ganze sollte möglichst Synchron laufen.
    GUI beenden geht auch nicht solange Progress bzw. Countdown läuft.
    Vieleicht gibs da noch eine besssere Lösung wie mein Versuch ?

    Danke im voraus

    Gruß
    Abraham

    Einmal editiert, zuletzt von Abraham (5. April 2013 um 21:02)

  • Ein bissle Mathe und dein Problem ist gelöst:

    Spoiler anzeigen
    [autoit]


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

    [/autoit] [autoit][/autoit] [autoit]

    $fill = 15000

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("My GUI")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    $ID_1 = GUICtrlCreateButton("Countdown", 10, 25, 100)
    $ID_2 = GUICtrlCreateButton("Progress", 10, 55, 100)
    $progress = GUICtrlCreateProgress(70, 0, 200, 20)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $ID_1
    _sleep(30000)
    Case $ID_2
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _sleep($time)
    $tstart = TimerInit()
    $stime = $time
    Do
    GUICtrlCreateLabel("Zeit : " & $stime / 1000 & " sec", 0, 2)
    Sleep(1000)
    $stime -= 1000
    GUICtrlSetData($progress, Floor(100 * (($time - $stime) / $time)))
    Until TimerDiff($tstart) >= $time
    EndFunc ;==>_sleep

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Hallo Abraham,

    ich habe mal deine Zeitausgabe und die Progressbar synchronisiert:

    Spoiler anzeigen
    [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    $fill = 15000

    [/autoit] [autoit][/autoit] [autoit]

    GUICreate("My GUI")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    $idLblRest = GUICtrlCreateLabel("Zeit : ", 5, 5, 60, 20)
    $idBtnCountDown = GUICtrlCreateButton("Countdown", 10, 35, 100, 22)
    $idProgress = GUICtrlCreateProgress(70, 5, 200, 20)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $idBtnCountDown
    $iSec = 30000
    $iRest = $iSec
    GUICtrlSetData($idLblRest, "Zeit : " & Int($iRest / 1000) & " sec")
    GUICtrlSetData($idProgress, 0)
    $iStart = TimerInit()
    _sleep()
    $iDiff = TimerDiff($iStart)
    ConsoleWrite($iDiff&@CRLF)
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _sleep()
    Local $iStart = TimerInit(), $iDiff
    Do
    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit ;damit das Programm auch beendet werden kann
    Sleep(10)
    $iDiff = TimerDiff($iStart)
    Until $iDiff > 995
    $iRest -= $iDiff
    GUICtrlSetData($idLblRest, "Zeit : " & Int($iRest / 1000) & " sec")
    GUICtrlSetData($idProgress, 100 - ($iRest / $iSec * 100))
    If $iRest > 0 Then _Sleep()
    EndFunc ;==>_sleep

    [/autoit]

    viel Spass damit autoBert

    • Offizieller Beitrag

    Egal ob zu spät, hier Variante 3:

    Spoiler anzeigen
    [autoit]

    #Region - Timestamp
    ; 2013-04-05 21:09:07
    #EndRegion

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    $Timer = 30
    $EndTimer = False
    GUICreate("My GUI")

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()
    $ID_1 = GUICtrlCreateButton("Countdown", 10, 25, 100)
    $progress = GUICtrlCreateProgress(70, 0, 200, 20)

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $ID_1
    AdlibRegister("_Sleep", 1000)

    [/autoit] [autoit][/autoit] [autoit]

    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    If $EndTimer Then
    MsgBox(0, "Info", "Timer abgelaufen", 1)
    $EndTimer = False
    EndIf
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _sleep()
    Local Static $sTimer = $Timer

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel("Zeit : " & $sTimer & " sec", 0, 2)
    GUICtrlSetData($progress, Floor(100 * (($Timer - $sTimer) / $Timer)))
    $sTimer -= 1
    If $sTimer < 0 Then
    AdlibUnRegister("_Sleep")
    $EndTimer = True
    $sTimer = $Timer
    EndIf
    EndFunc ;==>_sleep

    [/autoit]