Hallo zusammen,
ich versuche mir einen Timer zu basteln, dank der _countdown Funktion von bugfix hab ich es nun auch soweit hinbekommen.
Beim ersten Start funktioniert das ganze soweit bereits wie es soll.
Jetzt wollte ich das ganze noch soweit modifizieren das man die Timer Zeit mittels einer extra GUI ändern kann. Und da beginnt nun mein Problem, sobald die Änderung mittels Button abgeschickt wird und der Timer erfolgreich neu startet, funktioniert keine der anderen Dinge in der GUI.
Edit/Stop/Close und ebenso das bewegen des Fensters ist dann nicht mehr möglich.
Hoffe ich konnte mein Problem annähernd beschreiben
Danke
Spoiler anzeigen
#include <APIConstants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Local $tGUI, $tLabel_timer
Local $WinXPos, $WinYPos, $WinPos
Local $sGUI, $iH, $iM, $iS
Local $sec = 0, $min = 10, $hr = 0, $stopit = 0
Local $inifile = @ScriptDir & "\MyTimer.ini"
_showTimer()
[/autoit] [autoit][/autoit] [autoit]While 1
Sleep(100)
WEnd
; #FUNCTION# ===================================================================
; Description ...: show timer window
; ==============================================================================
Func _showTimer()
$tGUI = GUICreate("Timer", 300, 82, -1, -1, $WS_POPUP)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_PrimeDown")
GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseApp")
$tLabel_timer = GUICtrlCreateLabel("00:00:00 h", 0, 17, 300, 65, $SS_CENTER)
GUICtrlSetBkColor(-1, 0xBFCDDB)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 40, 400, 0, "Roland")
GUICtrlCreateLabel("[Edit]", 0, 1, 30, 15)
GUICtrlSetOnEvent(-1, "_showSetup")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("[Stop]", (300 / 2) - 17, 1, 34, 15)
GUICtrlSetOnEvent(-1, "_stopTimer")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("[Close]", 259, 1, 40, 15, $SS_RIGHT)
GUICtrlSetOnEvent(-1, "_closeApp")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
; alte Fensterposition laden und GUI verschieben
If $inifile <> "" Then
$WinXPos = IniRead($inifile, "Startwerte", "WinXPos", "")
$WinYPos = IniRead($inifile, "Startwerte", "WinYPos", "")
If $WinXPos <> "" And $WinYPos <> "" Then WinMove("Timer", "", $WinXPos, $WinYPos)
EndIf
_startCountDown()
EndFunc ;==>_showTimer
; #FUNCTION# ===================================================================
; Description ...: show Setup window
; ==============================================================================
Func _ShowSetup()
_stopTimer()
$sGUI = GUICreate("Settings", 256, 205, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseSetup")
GUICtrlCreateLabel('Stunden', 15, 48, 60, 17)
$iH = GUICtrlCreateInput('', 80, 45, 20, 20, $ES_NUMBER)
GUICtrlCreateLabel('Minuten', 15, 78, 60, 17)
$iM = GUICtrlCreateInput('', 80, 75, 20, 20, $ES_NUMBER)
GUICtrlCreateLabel('Sekunden', 15, 108, 60, 17)
$iS = GUICtrlCreateInput('', 80, 105, 20, 20, $ES_NUMBER)
GUICtrlCreateButton('Change time', 140, 15, 105, 25)
GUICtrlSetOnEvent(-1, "_closeSetup")
GUISetState(@SW_SHOW)
EndFunc ;==>_ShowSetup
; #FUNCTION# ===================================================================
; Description ...: Close setup window
; ==============================================================================
Func _CloseSetup()
If GUICtrlRead($iH) = '' Then
$hr = 0
Else
$hr = GUICtrlRead($iH)
EndIf
If GUICtrlRead($iM) = '' Then
$min = 0
Else
$min = GUICtrlRead($iM)
EndIf
If GUICtrlRead($iS) = '' Then
$sec = 0
Else
$sec = GUICtrlRead($iS)
EndIf
ConsoleWrite("H: " & $hr & @CRLF & "M: " & $min & @CRLF & "S: " & $sec & @CRLF)
GUIDelete($sGUI)
_startCountDown()
EndFunc ;==>_CloseSetup
[/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ===================================================================
; Description ...: close App and write position to ini file
; ==============================================================================
Func _CloseApp()
IniDelete($inifile, "Startwerte")
$WinPos = WinGetPos("Timer")
IniWrite($inifile, "Startwerte", "WinXPos", $WinPos[0])
IniWrite($inifile, "Startwerte", "WinYPos", $WinPos[1])
Exit
EndFunc ;==>_CloseApp
; #FUNCTION# ===================================================================
; Description ...: Start Countdown
; ==============================================================================
Func _startCountDown()
_CountDown($sec, $min, $hr, 0, True, $tLabel_timer)
EndFunc ;==>_startCountDown
; #FUNCTION# ===================================================================
; Description ...: Stop Timer
; ==============================================================================
Func _stopTimer()
$stopit = 1
EndFunc ;==>_stopTimer
; #FUNCTION# ===================================================================
; Description ...: makes GUI moveable with mouse
; ==============================================================================
Func _PrimeDown()
Local $DifX, $DifY, $MouseData = GUIGetCursorInfo(@GUI_WinHandle)
Local $WinPos = WinGetPos(@GUI_WinHandle)
Local $MPos = MouseGetPos()
$DifX = $MPos[0] - $WinPos[0]
$DifY = $MPos[1] - $WinPos[1]
While $MouseData[2]
$MPos = MouseGetPos()
$WinPos = WinGetPos(@GUI_WinHandle)
If ($WinPos[0] <> ($MPos[0] - $DifX)) Or ($WinPos[1] <> ($MPos[1] - $DifY)) Then
WinMove(@GUI_WinHandle, '', $MPos[0] - $DifX, $MPos[1] - $DifY)
EndIf
Sleep(15)
$MouseData = GUIGetCursorInfo(@GUI_WinHandle)
WEnd
;GUICtrlSetState($suchtext_id,$GUI_FOCUS)
EndFunc ;==>_PrimeDown
;----------------------------------------------------------------------------------------------------------------------
; Funktion _CountDown($SEC [, $MIN=0 [, $HOUR=0 [, $DAY=0 [, $VISIBLEDOWN=True [, $ALTERNATECTRL='TT']]]]])
;
; Beschreibung zählt vorgegebene Zeitspanne (Tage, Stunden, Minuten, Sekunden) herunter mit Anzeige Tooltip (Standard)
; oder Ausgabe in GUI-Ctrl; wahlweise Anzeige von Restzeit (Standard) oder abgelaufener Zeit
;
; Parameter $SEC: Sekunden
; optional $MIN: Minuten
; optional $HOUR: Stunden
; optional $DAY: Tage
; optional $VISIBLEDOWN: Ansicht (herunterzählen/heraufzählen)
; optional $ALTERNATECTRL: GUI-Ctrl in das die Ausgabe mittels GUICtrlSetData() ausgegeben wird
;
; Erfordernisse #include <Date.au3>
;
; Autor BugFix ([email='bugfix@autoit.de'][/email])
;----------------------------------------------------------------------------------------------------------------------
Func _CountDown($sec, $min = 0, $HOUR = 0, $day = 0, $VISIBLEDOWN = True, $ALTERNATECTRL = 'TT')
Local $Sekunden, $secShow, $end
$Sekunden = $sec + $min * 60 + $HOUR * 3600 + $day * 86400
$end = _DateAdd('s', $Sekunden, _NowCalc())
Local $message
Do
Sleep(100)
$sec = _DateDiff('s', _NowCalc(), $end)
If Not $VISIBLEDOWN Then
$secShow = $Sekunden - $sec
Else
$secShow = $sec
EndIf
Select
Case $secShow < 60
If $ALTERNATECTRL = 'TT' Then
ToolTip(StringFormat('%02u', $secShow) & ' s')
Else
GUICtrlSetData($ALTERNATECTRL, StringFormat('%02u', $secShow) & ' s')
EndIf
Case $secShow < 60 * 60
$message = StringFormat('%02u', Floor($secShow / 60)) & ':' & _
StringFormat('%02u', Mod($secShow, 60)) & ' min'
If $ALTERNATECTRL = 'TT' Then
ToolTip($message)
Else
GUICtrlSetData($ALTERNATECTRL, $message)
EndIf
Case $secShow < 60 * 60 * 24
$message = StringFormat('%02u', Floor($secShow / 3600)) & ':' & _
StringFormat('%02u', Floor(Mod($secShow, 3600) / 60)) & ':' & _
StringFormat('%02u', Mod(Mod($secShow, 3600), 60)) & ' h'
If $ALTERNATECTRL = 'TT' Then
ToolTip($message)
Else
GUICtrlSetData($ALTERNATECTRL, $message)
EndIf
Case Else
$message = Floor($secShow / 86400) & ' d / ' & _
StringFormat('%02u', Floor(Mod($secShow, 86400) / 3600)) & ':' & _
StringFormat('%02u', Floor(Mod(Mod($secShow, 86400), 3600) / 60)) & ':' & _
StringFormat('%02u', Mod(Mod(Mod($secShow, 86400), 3600), 60)) & ' h'
If $ALTERNATECTRL = 'TT' Then
ToolTip($message)
Else
GUICtrlSetData($ALTERNATECTRL, $message)
EndIf
EndSelect
Until $sec = 0 Or $stopit = 1
$stopit = 0
#cs
If $sec = 0 Then
GUICtrlSetData($tLabel_timer, " It's time")
SoundPlay(@ScriptDir & "\alarma.wav", 1)
EndIf
#ce
EndFunc ;==>_CountDown
Gruß Mks