﻿#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=stopwatch.ico
#AutoIt3Wrapper_Outfile=Spielzeit-Timer.exe
#AutoIt3Wrapper_Res_Description=Spielzeit-Timer
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Oscar (www.autoit.de)/geändert SCCSSF
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Res_Icon_Add=stopwatch.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#Region Includes
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <Sound.au3>
#include <StaticConstants.au3>
#include <Timers.au3>
#include <WinAPI.au3>
#include <WinAPIGdi.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Misc.au3>
#include <GuiButton.au3>
#include <EditConstants.au3>
#include '_ProgressEx.au3'
#include '_DateiEx.au3'
#EndRegion Includes

#Region single
If _Singleton("Timer", 1) = 0 Then
	Exit
EndIf
#EndRegion single

#Region Optionen
;#NoTrayIcon
Opt('MustDeclareVars', 1)
Opt('TrayMenuMode', 1)
Opt('GUIOnEventMode', 1)
Opt('TrayOnEventMode', 1)
#EndRegion Optionen

#Region Globale Variable
Global $iTimeCmdS
Global $iPauseCmdS
Global $iRoundCmdS
Global $aProgress1
Global $aProgress2
Global $aSound
Global $aSound1
Global $aSound2
Global $aSound3
Global $Datein1, $Datein2, $Datein3, $Datei_d1, $Datei_d2, $Datei_d3
Global $hBMP
Global $helpmenu
Global $hGui, $hGUi1, $hGUi2, $hGUi3
Global $idDown
Global $idDownP
Global $idUp, $idUpP
Global $idReset
Global $sound1
Global $sound2
Global $sound3
Global $idround
Global $iRound
Global $iTimerSeconds
Global $iTimerSecondsRes
Global $iTimerPause
Global $iTimerPauseRes
Global $iTimerStep
Global $iTimerDiv
Global $bTimerOn
Global $bTimerOnPause
Global $Setting_Menu
Global $Setting_Para
Global $Setting_exit
Global $Info
Global $idTime
Global $idTime1
Global $idTime1E
Global $idTime2
Global $idTime2E
Global $idTime3E
Global $idStop
Global $idStart
Global $iTimerSecond
Global $iSeconds
Global $iSecondsPause
Global $Liste1speichern, $Liste2speichern, $Liste3speichern, $Liste41speichern, $Liste4speichern, $Liste5speichern, $Liste6speichern
Global $SettingGui
#EndRegion Globale Variable

#Region Startparameter
;==> Übergabe der Start Parameter
;==> Hilfe "/?"
;==> Parameter 1 Spielzeit "/t"
;==> Parameter 2 Pausenzeit "/p"
;==> Parameter 3 Runden "/r"

Local $iTimeCmd, $iPauseCmd, $iRoundCmd
If $CMDLINE[0] Then
	For $i = 1 To $CMDLINE[0]
		Switch $CMDLINE[$i]
			Case '/?'
				MsgBox(0x40000, @ScriptName & ' Hilfe', _
						'Steuerbefehle zum Übertragen der Zeiten per Kommandoaufruf (cmd):' & @CRLF _
						 & @CRLF & '/t <Spielzeit in Sekunden>' _
						 & @CRLF & @TAB _
						 & @CRLF & '/p <Pausenzeit in Sekunden>')
				Exit
			Case '/t'
				If $CMDLINE[0] > $i Then
					$i += 1
					$iTimeCmd = Number(StringRegExpReplace($CmdLine[$i], '(\d+)', '\1'))
					If $iTimeCmd <> 0 Then
						$iTimeCmdS = $iTimeCmd
					EndIf
				EndIf

			Case '/p'
				If $CMDLINE[0] > $i Then
					$i += 1
					$iPauseCmd = Number(StringRegExpReplace($CmdLine[$i], '(\d+)', '\1'))
					If $iPauseCmd <> 0 Then
						$iPauseCmdS = $iPauseCmd
					EndIf
				EndIf
			Case '/r'
				If $CMDLINE[0] > $i Then
					$i += 1
					$iRoundCmd = Number(StringRegExpReplace($CmdLine[$i], '(\d+)', '\1'))
					If $iRoundCmd <> 0 Then
						$iRoundCmdS = $iRoundCmd
					EndIf
				EndIf
			Case Else
				MsgBox(0x40000, 'Ungültige Option', _
						'Command used:' & @CRLF & $CMDLINERAW & @CRLF & _
						@CRLF & 'Benutzen Sie /? für mehr Informationen.')
				; Exit
		EndSwitch
	Next
EndIf
#EndRegion Startparameter

_GDIPlus_Startup()

#Region Konstanten deklarieren
Global $__Restart = False
Global Const $sAppTitle = 'Spielzeit-Timer'
Global Const $sAppVersion = '0.3'
Global Const $sAppDate = '28.02.2019'
Global Const $sAppAuthor = 'Oscar (www.autoit.de) / SCCCSF'
Global Const $sAppDir = @AppDataDir & '\SP-Timer\'
If Not FileExists($sAppDir) Then MsgBox(262208, "Erster Start", "Unter Menü -> Einstellungen können Sie Ihre Standard Einstellunge vornehmen!")
If Not FileExists($sAppDir) Then DirCreate($sAppDir)
Global Const $sInifile = $sAppDir & 'Spielzeit-Timer.ini'
Global $b7SegmentFont = _Segment7new()
Global $t7SegmentFont = DllStructCreate('byte[' & BinaryLen($b7SegmentFont) & ']')
DllStructSetData($t7SegmentFont, 1, $b7SegmentFont)
Global $h7SegmentFont = _WinAPI_AddFontMemResourceEx(DllStructGetPtr($t7SegmentFont), DllStructGetSize($t7SegmentFont))
Global $hUpBitmap = _GDIPlus_BitmapCreateFromMemory(_uppng())
Global $hDownBitmap = _GDIPlus_BitmapCreateFromMemory(_downpng())
Global $sSoundfile = @TempDir & '\glocke.mp3'
If Not FileExists($sSoundfile) Then _glocke(True, @TempDir)
$aSound = _SoundOpen($sSoundfile)
Global Const $iAppDPI = RegRead('HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics', 'AppliedDPI')
Global Const $iRed = 0, $iYellow = 60, $iGreen = 120, $iBlue = -150 ; Farbwerte/HUE gegenueber dem roten Standardwert (Werte von -180 bis +180 sind moeglich)
Global Const $iWidth = 240, $iHeight = 360
#EndRegion Konstanten deklarieren

#Region globale Variablen
$iTimerSeconds = IniRead($sInifile, 'Config', 'TimerSeconds', 600)
If $iTimeCmdS <> 0 Then
	$iTimerSeconds = $iTimeCmdS
EndIf
$iTimerSecondsRes = $iTimerSeconds
$iTimerStep = IniRead($sInifile, 'Config', 'TimerStep', 10) ; In der Inidatei kann man die Schrittweite (in Sekunden) fuer die Timereinstellung festlegen
$iTimerDiv = IniRead($sInifile, 'Config', 'TimerDiv', 1) ; In der Inidatei kann man die Schrittweite (in Menuten) fuer die letzte Minute festelegen
$iTimerPause = IniRead($sInifile, 'Config', 'TimerPause', 300) ; In der Inidatei kann man die Schrittweite (in Sekunden) fuer die Pause festlegen
If $iPauseCmdS <> 0 Then
	$iTimerPause = $iPauseCmdS
EndIf
$iTimerPauseRes = $iTimerPause
$bTimerOn = False
$iSeconds = $iTimerSeconds
$bTimerOnPause = False
$iSecondsPause = $iTimerPause
$sound1 = IniRead($sInifile, 'Sound', 'letzte-Minute', $sSoundfile)
If Not FileExists($sound1) Then $sound1 = $sSoundfile
$aSound1 = _SoundOpen($sound1)
$sound2 = IniRead($sInifile, 'Sound', 'Spielende', $sSoundfile)
If Not FileExists($sound2) Then $sound2 = $sSoundfile
$aSound2 = _SoundOpen($sound2)
$sound3 = IniRead($sInifile, 'Sound', 'Pause', $sSoundfile)
If Not FileExists($sound3) Then $sound3 = $sSoundfile
$aSound3 = _SoundOpen($sound3)
$iRound = IniRead($sInifile, 'Config', 'Runden', 1) ; In der Inidatei kann man die Rounden Anzahl festlegen

#EndRegion globale Variablen

#Region löschen wenn nicht mehr benötigt
Global $iHalfT = 2
#EndRegion löschen wenn nicht mehr benötigt

#Region Fenster erstellen
_Fenster()

Func _Fenster()  ;Funktion Fenster
	If $iRound < 2 Then
		If $iHalfT = 1 Then
			_Fenster01()
		Else
			_Fenster02()
		EndIf
	Else
		If $iHalfT = 1 Then
			_FensterX1()
		Else
			_FensterX2()
		EndIf
	EndIf
EndFunc   ;==>_Fenster

Func _Fenster01() ;(keine Runden 1 Halbzeit)
	$hGui = GUICreate(StringFormat('%s  v%-3.3s', '01', $sAppTitle, $sAppVersion), $iWidth, $iHeight, -1, -1, -1)
	GUISetOnEvent($GUI_EVENT_CLOSE, _Minimize)
	GUISetOnEvent($GUI_EVENT_MINIMIZE, _Minimize)
	TraySetOnEvent(-7, "_Restore")
	GUISetBkColor(0x000000)
	GUISetIcon(@ScriptDir & '\stopwatch.ico', 0, $hGui)

	$Setting_Menu = GUICtrlCreateMenu("Menü")
	$Setting_Para = GUICtrlCreateMenuItem("Einstellungen", $Setting_Menu)
	GUICtrlSetOnEvent(-1, "_Settings")
	$Setting_exit = GUICtrlCreateMenuItem("Ende", $Setting_Menu)
	GUICtrlSetOnEvent(-1, "_Exit")
	$helpmenu = GUICtrlCreateMenu("?")
	$Info = GUICtrlCreateMenuItem("Version", $helpmenu)
	GUICtrlSetOnEvent(-1, "_showInfo")

	$idTime = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int($iTimerSeconds / 60), Mod($iTimerSeconds, 60)), 20, 12, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi1 = GUICtrlCreateLabel("Spielzeit", 30, 80, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)

	$idTime1 = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int(($iTimerSeconds - $iTimerDiv * 60) / 60), Mod($iTimerSeconds, 60)), 20, 120, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi2 = GUICtrlCreateLabel("letzte Minute", 30, 158, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)

	$idTime2 = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int($iTimerPause / 60), Mod($iTimerPause, 60)), 20, 200, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi3 = GUICtrlCreateLabel("Pause", 30, 268, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)


	$idUp = GUICtrlCreatePic('', $iWidth - 34, 6, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hUpBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idUp, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idDown = GUICtrlCreatePic('', $iWidth - 34, 34, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hDownBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idDown, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idUpP = GUICtrlCreatePic('', $iWidth - 34, 197, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerPauseSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hUpBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idUpP, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idDownP = GUICtrlCreatePic('', $iWidth - 34, 225, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerPauseSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hDownBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idDownP, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$aProgress1 = _ProgressEx_Create(10, 60, $iWidth - 20, 15, $PE_NOTEXT)
	_ProgressEx_SetData($aProgress1, 100, $iGreen)

	$aProgress2 = _ProgressEx_Create(10, 250, $iWidth - 20, 15, $PE_NOTEXT)
	_ProgressEx_SetData($aProgress2, 100, -0)

	$idReset = GUICtrlCreateButton('Reset', 10, 310, 50, 25)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_ResetTimer')

	$idStop = GUICtrlCreateButton('Stop', 65, 310, 50, 25)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_StopTimer')
	GUICtrlSetState($idStop, $GUI_DISABLE)

	$idStart = GUICtrlCreateButton('Start', $iWidth - 120, 310, 110, 25, $BS_DEFPUSHBUTTON)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_StartTimer')
EndFunc   ;==>_Fenster01

Func _FensterX1() ;(mehrere Runden 1 Halbzeit)
	$hGui = GUICreate(StringFormat('%s  v%-3.3s', 'X1', $sAppTitle, $sAppVersion), $iWidth, $iHeight, -1, -1, -1)
	GUISetOnEvent($GUI_EVENT_CLOSE, _Minimize)
	GUISetOnEvent($GUI_EVENT_MINIMIZE, _Minimize)
	TraySetOnEvent(-7, "_Restore")
	GUISetBkColor(0x000000)
	GUISetIcon(@ScriptDir & '\stopwatch.ico', 0, $hGui)

	$Setting_Menu = GUICtrlCreateMenu("Menü")
	$Setting_Para = GUICtrlCreateMenuItem("Einstellungen", $Setting_Menu)
	GUICtrlSetOnEvent(-1, "_Settings")
	$Setting_exit = GUICtrlCreateMenuItem("Ende", $Setting_Menu)
	GUICtrlSetOnEvent(-1, "_Exit")
	$helpmenu = GUICtrlCreateMenu("?")
	$Info = GUICtrlCreateMenuItem("Version", $helpmenu)
	GUICtrlSetOnEvent(-1, "_showInfo")

	$idTime = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int($iTimerSeconds / 60), Mod($iTimerSeconds, 60)), 20, 12, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi1 = GUICtrlCreateLabel("Spielzeit", 30, 80, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)

	$idTime1 = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int(($iTimerSeconds - $iTimerDiv * 60) / 60), Mod($iTimerSeconds, 60)), 20, 120, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi2 = GUICtrlCreateLabel("letzte Minute", 30, 158, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)

	$idTime2 = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int($iTimerPause / 60), Mod($iTimerPause, 60)), 20, 200, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi3 = GUICtrlCreateLabel("Pause", 30, 268, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)


	$idUp = GUICtrlCreatePic('', $iWidth - 34, 6, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hUpBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idUp, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idDown = GUICtrlCreatePic('', $iWidth - 34, 34, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hDownBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idDown, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idUpP = GUICtrlCreatePic('', $iWidth - 34, 197, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerPauseSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hUpBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idUpP, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idDownP = GUICtrlCreatePic('', $iWidth - 34, 225, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerPauseSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hDownBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idDownP, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$aProgress1 = _ProgressEx_Create(10, 60, $iWidth - 20, 15, $PE_NOTEXT)
	_ProgressEx_SetData($aProgress1, 100, $iGreen)

	$aProgress2 = _ProgressEx_Create(10, 250, $iWidth - 20, 15, $PE_NOTEXT)
	_ProgressEx_SetData($aProgress2, 100, -0)

	$idReset = GUICtrlCreateButton('Reset', 10, 310, 50, 25)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_ResetTimer')

	$idStop = GUICtrlCreateButton('Stop', 65, 310, 50, 25)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_StopTimer')
	GUICtrlSetState($idStop, $GUI_DISABLE)

	$idStart = GUICtrlCreateButton('Start', $iWidth - 120, 310, 110, 25, $BS_DEFPUSHBUTTON)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_StartTimer')
EndFunc   ;==>_FensterX1

Func _Fenster02() ;(keine Runden 2 Halbzeit)
	$hGui = GUICreate(StringFormat('%s  v%-3.3s', '02', $sAppTitle, $sAppVersion), $iWidth, $iHeight, -1, -1, -1)
	GUISetOnEvent($GUI_EVENT_CLOSE, _Minimize)
	GUISetOnEvent($GUI_EVENT_MINIMIZE, _Minimize)
	TraySetOnEvent(-7, "_Restore")
	GUISetBkColor(0x000000)
	GUISetIcon(@ScriptDir & '\stopwatch.ico', 0, $hGui)

	$Setting_Menu = GUICtrlCreateMenu("Menü")
	$Setting_Para = GUICtrlCreateMenuItem("Einstellungen", $Setting_Menu)
	GUICtrlSetOnEvent(-1, "_Settings")
	$Setting_exit = GUICtrlCreateMenuItem("Ende", $Setting_Menu)
	GUICtrlSetOnEvent(-1, "_Exit")
	$helpmenu = GUICtrlCreateMenu("?")
	$Info = GUICtrlCreateMenuItem("Version", $helpmenu)
	GUICtrlSetOnEvent(-1, "_showInfo")

	$idTime = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int($iTimerSeconds / 60), Mod($iTimerSeconds, 60)), 20, 12, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi1 = GUICtrlCreateLabel("Spielzeit", 30, 80, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)

	$idTime1 = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int(($iTimerSeconds - $iTimerDiv * 60) / 60), Mod($iTimerSeconds, 60)), 20, 120, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi2 = GUICtrlCreateLabel("letzte Minute", 30, 158, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)

	$idTime2 = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int($iTimerPause / 60), Mod($iTimerPause, 60)), 20, 200, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi3 = GUICtrlCreateLabel("Pause", 30, 268, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)


	$idUp = GUICtrlCreatePic('', $iWidth - 34, 6, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hUpBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idUp, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idDown = GUICtrlCreatePic('', $iWidth - 34, 34, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hDownBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idDown, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idUpP = GUICtrlCreatePic('', $iWidth - 34, 197, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerPauseSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hUpBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idUpP, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idDownP = GUICtrlCreatePic('', $iWidth - 34, 225, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerPauseSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hDownBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idDownP, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$aProgress1 = _ProgressEx_Create(10, 60, $iWidth - 20, 15, $PE_NOTEXT)
	_ProgressEx_SetData($aProgress1, 100, $iGreen)

	$aProgress2 = _ProgressEx_Create(10, 250, $iWidth - 20, 15, $PE_NOTEXT)
	_ProgressEx_SetData($aProgress2, 100, -0)

	$idReset = GUICtrlCreateButton('Reset', 10, 310, 50, 25)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_ResetTimer')

	$idStop = GUICtrlCreateButton('Stop', 65, 310, 50, 25)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_StopTimer')
	GUICtrlSetState($idStop, $GUI_DISABLE)

	$idStart = GUICtrlCreateButton('Start', $iWidth - 120, 310, 110, 25, $BS_DEFPUSHBUTTON)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_StartTimer')
EndFunc   ;==>_Fenster02

Func _FensterX2() ;(mehrere Runden 2 Halbzeit)
	$hGui = GUICreate(StringFormat('%s  v%-3.3s', 'X2', $sAppTitle, $sAppVersion), $iWidth, $iHeight, -1, -1, -1)
	GUISetOnEvent($GUI_EVENT_CLOSE, _Minimize)
	GUISetOnEvent($GUI_EVENT_MINIMIZE, _Minimize)
	TraySetOnEvent(-7, "_Restore")
	GUISetBkColor(0x000000)
	GUISetIcon(@ScriptDir & '\stopwatch.ico', 0, $hGui)
	GUISetState(@SW_SHOW)
	$Setting_Menu = GUICtrlCreateMenu("Menü")
	$Setting_Para = GUICtrlCreateMenuItem("Einstellungen", $Setting_Menu)
	GUICtrlSetOnEvent(-1, "_Settings")
	$Setting_exit = GUICtrlCreateMenuItem("Ende", $Setting_Menu)
	GUICtrlSetOnEvent(-1, "_Exit")
	$helpmenu = GUICtrlCreateMenu("?")
	$Info = GUICtrlCreateMenuItem("Version", $helpmenu)
	GUICtrlSetOnEvent(-1, "_showInfo")

	$idTime = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int($iTimerSeconds / 60), Mod($iTimerSeconds, 60)), 20, 12, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi1 = GUICtrlCreateLabel("Spielzeit", 30, 80, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)

	$idTime1 = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int(($iTimerSeconds - $iTimerDiv * 60) / 60), Mod($iTimerSeconds, 60)), 20, 120, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi2 = GUICtrlCreateLabel("letzte Minute", 30, 158, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)

	$idTime2 = GUICtrlCreateLabel(StringFormat('%02d:%02d', Int($iTimerPause / 60), Mod($iTimerPause, 60)), 20, 200, $iWidth - 60, 44, $SS_CENTER)
	GUICtrlSetColor(-1, 0x22FF22)
	GUICtrlSetFont(-1, 40 / $iAppDPI * 80, 400, 0, 'Segment7')
	$hGUi3 = GUICtrlCreateLabel("Pause", 30, 268, 172, 33, $SS_CENTER)
	GUICtrlSetColor(-1, 0xFEFF22)
	GUICtrlSetFont(-1, 20)


	$idUp = GUICtrlCreatePic('', $iWidth - 34, 6, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hUpBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idUp, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idDown = GUICtrlCreatePic('', $iWidth - 34, 34, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hDownBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idDown, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idUpP = GUICtrlCreatePic('', $iWidth - 34, 197, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerPauseSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hUpBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idUpP, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$idDownP = GUICtrlCreatePic('', $iWidth - 34, 225, 24, 24)
	GUICtrlSetOnEvent(-1, '_ChangeTimerPauseSeconds')
	$hBMP = _GDIPlus_BitmapCreateDIBFromBitmap($hDownBitmap)
	_WinAPI_DeleteObject(GUICtrlSendMsg($idDownP, $STM_SETIMAGE, $IMAGE_BITMAP, $hBMP))
	_WinAPI_DeleteObject($hBMP)

	$aProgress1 = _ProgressEx_Create(10, 60, $iWidth - 20, 15, $PE_NOTEXT)
	_ProgressEx_SetData($aProgress1, 100, $iGreen)

	$aProgress2 = _ProgressEx_Create(10, 250, $iWidth - 20, 15, $PE_NOTEXT)
	_ProgressEx_SetData($aProgress2, 100, -0)

	$idReset = GUICtrlCreateButton('Reset', 10, 310, 50, 25)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_ResetTimer')

	$idStop = GUICtrlCreateButton('Stop', 65, 310, 50, 25)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_StopTimer')
	GUICtrlSetState($idStop, $GUI_DISABLE)

	$idStart = GUICtrlCreateButton('Start', $iWidth - 120, 310, 110, 25, $BS_DEFPUSHBUTTON)
	GUICtrlSetFont(-1, 12 / $iAppDPI * 96, 600, 0, 'Tahoma')
	GUICtrlSetOnEvent(-1, '_StartTimer')
EndFunc   ;==>_FensterX2

#EndRegion Fenster erstellen

#Region Fenster anzeigen und auf das Schliessen warten (der Rest ist funktionsgesteuert)
Global $aAccelKeys[2][2] = [['{UP}', $idUp], ['{DOWN}', $idDown]]
GUISetAccelerators($aAccelKeys)
GUISetState(@SW_SHOW, $hGui)
_Timer_SetTimer($hGui, 1000, '_ChangeTimer')
_Timer_SetTimer($hGui, 1000, '_ChangeTimerPause')
WinWaitClose($hGui)
Exit
#EndRegion Fenster anzeigen und auf das Schliessen warten (der Rest ist funktionsgesteuert)

#Region Funktionen
Func _CloseMainGui()
	_Timer_KillAllTimers($hGui)
	_WinAPI_RemoveFontMemResourceEx($h7SegmentFont)
	$t7SegmentFont = 0
	_GDIPlus_BitmapDispose($hUpBitmap)
	_GDIPlus_BitmapDispose($hDownBitmap)
	_GDIPlus_Shutdown()
	_SoundClose($aSound)
	_SoundClose($aSound1)
	_SoundClose($aSound2)
	_SoundClose($aSound3)
	GUIDelete($hGui)
EndFunc   ;==>_CloseMainGui

Func _ChangeTimer($hWnd, $iMsg, $iIDTimer, $iTime, $idTime1, $idTime2, $iSeconds)
	If Not $bTimerOn Then Return
	$iSeconds -= 1
	GUICtrlSetData($idTime, StringFormat('%02d:%02d', Int($iSeconds / 60), Mod($iSeconds, 60)))

	If (($iSeconds - $iTimerDiv * 60) / 60) > 0 Then
		GUICtrlSetData($idTime1, StringFormat('%02d:%02d', Int(($iSeconds - $iTimerDiv * 60) / 60), Mod($iSeconds, 60)))
	Else
		GUICtrlSetData($idTime1, '00:00')
	EndIf

	_ProgressEx_SetData($aProgress1, 100 / $iTimerSeconds * $iSeconds, $iGreen)

	If (($iSeconds - $iTimerDiv * 60) / 60) = 0 Then
		_SoundPlay($aSound1)
	EndIf
	If $iSeconds = 0 Then
		$bTimerOn = False
		_SoundPlay($aSound2)
		$bTimerOnPause = True
	EndIf
EndFunc   ;==>_ChangeTimer

Func _ChangeTimerPause($hWnd, $iMsg, $iIDTimer, $idTime1, $idTime2, $iSecondsPause)
	If Not $bTimerOnPause Then Return
	$iSecondsPause -= 1
	GUICtrlSetData($idTime2, StringFormat('%02d:%02d', Int($iSecondsPause / 60), Mod($iSecondsPause, 60)))
	
	_ProgressEx_SetData($aProgress2, 100 / $iTimerPause * $iSecondsPause, -0)

	If $iSecondsPause = 0 Then
		$bTimerOnPause = False
		_SoundPlay($aSound3)
		_StopTimer()
		GUICtrlSetState($idStart, $GUI_DISABLE)
	EndIf
EndFunc   ;==>_ChangeTimerPause

Func _ChangeTimerSeconds()
	If $bTimerOn Then Return
	$iTimerSeconds += (@GUI_CtrlId = $idUp ? 1 : -1) * $iTimerStep
	If $iTimerSeconds < $iTimerStep Then $iTimerSeconds = 6000 - $iTimerStep
	If $iTimerSeconds > 6000 - $iTimerStep Then $iTimerSeconds = $iTimerStep
	$iSeconds = $iTimerSeconds
	GUICtrlSetData($idTime, StringFormat('%02d:%02d', Int($iSeconds / 60), Mod($iSeconds, 60)))
	GUICtrlSetData($idTime1, StringFormat('%02d:%02d', Int(($iSeconds - $iTimerDiv * 60) / 60), Mod($iSeconds, 60)))
EndFunc   ;==>_ChangeTimerSeconds

Func _ChangeTimerPauseSeconds()
	If $bTimerOnPause Then Return
	$iTimerPause += (@GUI_CtrlId = $idUpP ? 1 : -1) * $iTimerStep
	If $iTimerPause < $iTimerStep Then $iTimerPause = 6000 - $iTimerStep
	If $iTimerPause > 6000 - $iTimerStep Then $iTimerPause = $iTimerStep
	$iSecondsPause = $iTimerPause
	GUICtrlSetData($idTime2, StringFormat('%02d:%02d', Int($iSecondsPause / 60), Mod($iSecondsPause, 60)))
EndFunc   ;==>_ChangeTimerPauseSeconds

Func _ResetTimer()
	
	GUICtrlSetData($idTime, StringFormat('%02d:%02d', Int($iTimerSecondsRes / 60), Mod($iTimerSecondsRes, 60)))
	GUICtrlSetData($idTime1, StringFormat('%02d:%02d', Int(($iTimerSecondsRes - $iTimerDiv * 60) / 60), Mod($iTimerSecondsRes, 60)))
	GUICtrlSetData($idTime2, StringFormat('%02d:%02d', Int($iTimerPauseRes / 60), Mod($iTimerPauseRes, 60)))

	$iTimerSecond = $iTimerSecondsRes
	$iSeconds = $iTimerSecondsRes
	$iTimerPause = $iTimerPauseRes
	$iSecondsPause = $iTimerPauseRes

	$bTimerOn = False
	$bTimerOnPause = False

	GUICtrlSetState($idStart, $GUI_ENABLE)
	GUICtrlSetState($idStop, $GUI_DISABLE)

	_ProgressEx_SetData($aProgress1, 100, $iGreen)
	_ProgressEx_SetData($aProgress2, 100, 0)

EndFunc   ;==>_ResetTimer

Func _StopTimer()
	$bTimerOn = False
	$bTimerOnPause = False
	GUICtrlSetState($idStart, $GUI_ENABLE)
	GUICtrlSetState($idStop, $GUI_DISABLE)
	GUICtrlSetState($idReset, $GUI_ENABLE)
	GUICtrlSetState($Setting_Para, $GUI_ENABLE)

EndFunc   ;==>_StopTimer

Func _StartTimer()
	If $iSeconds = 0 Then
		$bTimerOnPause = True
	Else
		$bTimerOn = True
	EndIf
	GUICtrlSetState($idStart, $GUI_DISABLE)
	GUICtrlSetState($idReset, $GUI_DISABLE)
	GUICtrlSetState($Setting_Para, $GUI_DISABLE)
	GUICtrlSetState($idStop, $GUI_ENABLE)
EndFunc   ;==>_StartTimer

#EndRegion Funktionen

#Region Setting Menue
Func _settings()
	
	GUISetState(@SW_HIDE, $hGui)

	$sound1 = IniRead($sInifile, 'Sound', 'Spielanfang', "")
	$sound2 = IniRead($sInifile, 'Sound', 'Spielende', "")
	$sound3 = IniRead($sInifile, 'Sound', 'Pause', "")
	$idround = IniRead($sInifile, 'Config', 'Runden', "1")
	$idTime1E = IniRead($sInifile, 'Config', 'TimerSeconds', "600")
	$idTime2E = IniRead($sInifile, 'Config', 'TimerPause', "300") ; In der Inidatei kann man die Schrittweite (in Sekunden) fuer die Pausenzeit festlegen
	$idTime3E = IniRead($sInifile, 'Config', 'TimerStep', "10") ; In der Inidatei kann man die Schrittweite (in Sekunden) fuer die Timereinstellung festlegen
	
	$SettingGui = GUICreate(StringFormat('%s  v%-3.3s', "Einstellungen", $sAppVersion), 450, 360, -1, -1, -1)
	;==>_Sound 1
	Local $Label1 = GUICtrlCreateLabel("Sound-letzte-Minute", 8, 15, 150)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	$Liste1speichern = GUICtrlCreateInput($sound1, 8, 40, 350, 21)
	$Datein1 = GUICtrlCreateButton("...", 370, 40, 25, 21)
	GUICtrlSetOnEvent(-1, "_settings_d1")

	;==>_Sound 2
	Local $Label2 = GUICtrlCreateLabel("Sound-Spielende", 8, 70, 150)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	$Liste2speichern = GUICtrlCreateInput($sound2, 8, 95, 350, 21)
	$Datein2 = GUICtrlCreateButton("...", 370, 95, 25, 21)
	GUICtrlSetOnEvent(-1, "_settings_d2")

	;==>_Sound 3
	Local $Label3 = GUICtrlCreateLabel("Sound-Pausen-Ende", 8, 125, 150)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	$Liste3speichern = GUICtrlCreateInput($sound3, 8, 150, 350, 21)
	$Datein3 = GUICtrlCreateButton("...", 370, 150, 25, 21)
	GUICtrlSetOnEvent(-1, "_settings_d3")

	;==>_Spielzeit (Voreinstellung)
	Local $Label4 = GUICtrlCreateLabel("Spielzeit", 8, 180, 150)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	$Liste4speichern = GUICtrlCreateInput($idTime1E, 8, 205, 53, 21, BitOR($ES_CENTER, $ES_NUMBER), $WS_EX_CLIENTEDGE)
	GUICtrlCreateLabel("in Sekunden", 86, 205, 100, 15, -1, -1)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	
	;==>_Rundenanzahl (Voreinstellung)
	Local $Label41 = GUICtrlCreateLabel("Rundenanzahl", 233, 180, 150)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	$Liste41speichern = GUICtrlCreateInput($idround, 233, 205, 53, 21, BitOR($ES_CENTER, $ES_NUMBER), $WS_EX_CLIENTEDGE)
	GUICtrlCreateLabel("Anzahl", 311, 205, 100, 15, -1, -1)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	
	;==>_Pausenzeit (Voreinstellung)
	Local $Label5 = GUICtrlCreateLabel("Pausenzeit", 8, 230, 150)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	$Liste5speichern = GUICtrlCreateInput($idTime2E, 8, 255, 53, 21, BitOR($ES_CENTER, $ES_NUMBER), $WS_EX_CLIENTEDGE)
	GUICtrlCreateLabel("in Sekunden", 86, 255, 100, 15, -1, -1)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	
	;==>Verstellung (Voreinstellung)
	Local $Label6 = GUICtrlCreateLabel("Verstellung", 8, 280, 150)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	$Liste6speichern = GUICtrlCreateInput($idTime3E, 8, 305, 53, 21, BitOR($ES_CENTER, $ES_NUMBER), $WS_EX_CLIENTEDGE)
	GUICtrlCreateLabel("in Sekunden", 86, 305, 100, 15, -1, -1)
	GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
	
	;==>_Speichern/Abbrechen
	Local $Speichern1 = GUICtrlCreateButton("Speichern", 250, 310, 65, 25)
	GUICtrlSetOnEvent(-1, "_settings_save")
	Local $Abbrechen = GUICtrlCreateButton("Abbrechen", 330, 310, 65, 25)
	GUICtrlSetOnEvent(-1, "_settings_end")
	GUISetState(@SW_SHOW)
	GUISetOnEvent($GUI_EVENT_CLOSE, '_settings_end')

EndFunc   ;==>_settings

Func _settings_d1()
	$Datei_d1 = FileOpenDialog("Bitte Sound Wählen", "c:\", "Sound (*.mp3)", 1 + 2) ;=>Datei auswählen
	GUICtrlSetData($Liste1speichern, $Datei_d1) ;=> Datei Anzeigen
EndFunc   ;==>_settings_d1

Func _settings_d2()
	$Datei_d2 = FileOpenDialog("Bitte Sound Wählen", "c:\", "Sound (*.mp3)", 1 + 2) ;=>Datei auswählen
	GUICtrlSetData($Liste2speichern, $Datei_d2) ;=> Datei Anzeigen
EndFunc   ;==>_settings_d2

Func _settings_d3()
	$Datei_d3 = FileOpenDialog("Bitte Sound Wählen", "c:\", "Sound (*.mp3)", 1 + 2) ;=>Datei auswählen
	GUICtrlSetData($Liste3speichern, $Datei_d3) ;=> Datei Anzeigen
EndFunc   ;==>_settings_d3

Func _settings_end()
	GUIDelete($SettingGui)
	GUISetState(@SW_SHOW, $hGui)
EndFunc   ;==>_settings_end

Func _settings_save()
	Local $L1sp = GUICtrlRead($Liste1speichern, 1)
	If $L1sp = "" Then
	Else
		IniWrite($sInifile, 'Sound', 'letzte-Minute', GUICtrlRead($Liste1speichern))
	EndIf
	
	Local $L2sp = GUICtrlRead($Liste2speichern, 1)
	If $L2sp = "" Then
	Else
		IniWrite($sInifile, 'Sound', 'Spielende', GUICtrlRead($Liste2speichern))
	EndIf

	Local $L3sp = GUICtrlRead($Liste3speichern, 1)
	If $L3sp = "" Then
	Else
		IniWrite($sInifile, 'Sound', 'Pause', GUICtrlRead($Liste3speichern))
	EndIf

	Local $L4sp = GUICtrlRead($Liste4speichern, 1)
	If $L4sp = "" Then
	ElseIf $L4sp = 0 Then
	Else
		IniWrite($sInifile, 'Config', 'TimerSeconds', GUICtrlRead($Liste4speichern))
	EndIf

	Local $L41sp = GUICtrlRead($Liste41speichern, 1)
	If $L41sp = "" Then
	ElseIf $L41sp = 0 Then
	Else
		IniWrite($sInifile, 'Config', 'Runden', GUICtrlRead($Liste41speichern))
		If $L41sp <> $iRound Then
			Local $restart = 1
		Else
			Local $restart = 0
		EndIf
	EndIf
	
	Local $L5sp = GUICtrlRead($Liste5speichern, 1)
	If $L5sp = "" Then
	ElseIf $L5sp = 0 Then
	Else
		IniWrite($sInifile, 'Config', 'TimerPause', GUICtrlRead($Liste5speichern))
	EndIf

	Local $L6sp = GUICtrlRead($Liste5speichern, 1)
	If $L6sp = "" Then
	ElseIf $L6sp = 0 Then
	Else
		IniWrite($sInifile, 'Config', 'TimerStep', GUICtrlRead($Liste6speichern))
	EndIf

	$sound1 = IniRead($sInifile, 'Sound', 'letzte-Minute', "")
	$sound2 = IniRead($sInifile, 'Sound', 'Spielende', "")
	$sound3 = IniRead($sInifile, 'Sound', 'Pause', "")
	$iRound = IniRead($sInifile, 'Config', 'Runden', "")
	$iTimerSeconds = IniRead($sInifile, 'Config', 'TimerSeconds', "")
	$iTimerSecondsRes = $iTimerSeconds
	$iTimerPause = IniRead($sInifile, 'Config', 'TimerPause', "")
	$iTimerPauseRes = $iTimerPause
	$iTimerStep = IniRead($sInifile, 'Config', 'TimerStep', "")
	
	GUIDelete($SettingGui)
	
;	MsgBox(1, "", $restart)
	If $restart = 1 Then
		GUIDelete($hGui)
		_ScriptRestart()
	Else
		GUISetState(@SW_SHOW, $hGui)
		_ResetTimer()
	EndIf
EndFunc   ;==>_settings_save
#EndRegion Setting Menue

Func _ScriptRestart($fExit = 1)     ;thanks to Yashied and UEZ
	Local $pid
	If Not $__Restart Then
		If @Compiled Then
			$pid = Run(@ScriptFullPath & ' ' & $CmdLineRaw, @ScriptDir, Default, 1)
		Else
			$pid = Run(@AutoItExe & ' "' & @ScriptFullPath & '" ' & $CmdLineRaw, @ScriptDir, Default, 1)
		EndIf
		If @error Then
			Return SetError(@error, 0, 0)
		EndIf
		StdinWrite($pid, @AutoItPID)
	EndIf
	$__Restart = 1
	If $fExit Then
		Sleep(50)
	EndIf
	Return 1
EndFunc   ;==>_ScriptRestart
#Region Menue
Func _Showinfo()
	MsgBox(0, "Info", "Version " & $sAppVersion & @CRLF & $sAppDate & @CRLF & $sAppAuthor)
EndFunc   ;==>_Showinfo

Func _Exit()
	_CloseMainGui()
EndFunc   ;==>_Exit

Func _Minimize()
	TraySetState(4)
	GUISetState(@SW_HIDE)
EndFunc   ;==>_Minimize

Func _Restore()
	TraySetState(8)
	GUISetState(@SW_SHOW)
EndFunc   ;==>_Restore
#EndRegion Menue

