Ich hatte mal eine Stoppuhr erstellt. Ist ja grundsätzlich dasselbe Prinzip.
Schau es dir mal an, vielleicht bringt es dich weiter ![]()
Spoiler anzeigen
#include <GUIConstants.au3>
Global $start, $UsedTime, $diff_Alt = 0
Global $SetTime = False, $Break = False, $Pause = False, $Run = True
$GUI = GUICreate('Stoppuhr', 400, 100, -1, -1)
$Time = GUICtrlCreateInput('00:00:00,000', 100, 20, 200, 20, BitOR($ES_CENTER,$ES_READONLY))
$bStart = GUICtrlCreateButton('Start', 40, 60, 80, 20)
$bBreak = GUICtrlCreateButton('Unterbrechen', 160, 60, 80, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
$bPause = GUICtrlCreateButton('Pause', 280, 60, 80, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
GUISetState()
While True
$msg = GUIGetMsg()
If $SetTime Then $UsedTime = SetTime()
Switch $msg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $bStart ; Start/Stop Messung absolut
$Run = Not $Run
If $Run Then
$SetTime = False
SetTime()
GUICtrlSetData($bStart, 'Start')
GUICtrlSetState($bBreak, $GUI_DISABLE)
GUICtrlSetState($bPause, $GUI_DISABLE)
Else
$SetTime = True
$start = TimerInit()
GUICtrlSetData($bStart, 'Stop')
GUICtrlSetState($bBreak, $GUI_ENABLE)
GUICtrlSetState($bPause, $GUI_ENABLE)
EndIf
Case $bBreak ; nur Anzeige wird angehalten (z.B. Rundenmessung)
$Break = Not $Break
If $Break Then
$SetTime = False
GUICtrlSetData($bBreak, 'Fortsetzen')
GUICtrlSetState($bPause, $GUI_DISABLE)
Else
$SetTime = True
GUICtrlSetData($bBreak, 'Unterbrechen')
GUICtrlSetState($bPause, $GUI_ENABLE)
EndIf
Case $bPause ; Messung wird angehalten (Additionsmessung)
$Pause = Not $Pause
If $Pause Then
$diff_Alt = $UsedTime ; abgelaufene Zeit aufaddieren
$SetTime = False
GUICtrlSetData($bPause, 'Weiter')
GUICtrlSetState($bBreak, $GUI_DISABLE)
Else
$SetTime = True
$start = TimerInit() ; Zeitmessung neu initialisieren
GUICtrlSetData($bPause, 'Pause')
GUICtrlSetState($bBreak, $GUI_ENABLE)
EndIf
EndSwitch
WEnd
Func SetTime()
Local $diff = TimerDiff($start)/1000 + $diff_Alt
Local $hour = 0
Local $min = 0
Local $sec = Floor($diff)
Local $rest = ($diff-$sec)*1000
Local $secShow, $minShow, $hourShow
If $sec > 59 Then
$min = Floor($sec/60)
$secShow = Mod($sec, 60)
ElseIf $sec > 3599 Then
$hourShow = Mod(Mod($sec,3600),60)
$minShow = Floor(Mod($sec,3600)/60)
$secShow = Floor($sec/3600)
Else
$secShow = $sec
$minShow = $min
$hourShow = $hour
EndIf
GUICtrlSetData($Time, StringFormat('%02u', $hourShow) & ':' & StringFormat('%02u', $minShow) & ':' & StringFormat('%02u', $secShow) & ',' & StringFormat('%03u', $rest))
Return $diff ; gibt abgelaufene Zeit als absolute Differenz zurück
EndFunc