#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\Mes documents\clock-menu-icon.ico #AutoIt3Wrapper_outfile=TimerOff.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Res_Description=Timer to switch your computer off #AutoIt3Wrapper_Res_Fileversion=2.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=Linvi company #AutoIt3Wrapper_Res_Field=Version 2.0|You can now stop the timer - Timer can be change while launched - Add alarm option when the timer ended - TimerOff now minimize into the TrayMenu - You can launch, stop, resume, quit or set options from the TrayMenu - Add Quick Launch Menu - The Shutdown Actions are now forced. #AutoIt3Wrapper_Res_Field=Version 1.4.1|Bugs correction about the timer display #AutoIt3Wrapper_Res_Field=Version 1.4|Ajout de l'option Mise en Veille #AutoIt3Wrapper_Res_Field=Version 1.3|Bugs correction - Add: Timer - Add: Hour Option - Corrected: It's now possible to modify the Turn Off Option when the Timer is already lauched #AutoIt3Wrapper_Res_Field=Version 1.2|Add: Options to Turn Off the computer - Add: Time decounter #AutoIt3Wrapper_Res_Field=Version 1.1|Add: Easy choice of time #AutoIt3Wrapper_Res_Field=Version 1.0|Timer which switch off the computer after a sleep #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include #include Global $GUI = GUICreate("TimerOff", 400, 200, -1, -1, $WS_OVERLAPPEDWINDOW) Global $Time, $sTime, $Shut1, $Shut2, $Shut3, $Shut4, $Shut5, $Hour, $Min, $Sec, $HourT, $MinT, $SecT, $ShutValue, $OkValue Global $TrayButton, $Tray1, $Tray2, $Tray3, $Tray4, $Tray5 Global $Go30, $Go45, $Go60, $Ok, $IHour, $IMin, $ISec, $Browse, $Input Init() InitTray() GUISetState(@SW_SHOW) While 1 Global $nMsg = GUIGetMsg() Set_Time() Switch $nMsg Case $Ok,$TrayButton,$Go30, $Go45, $Go60 If (($nMsg <> $Ok) And ($nMsg <> $TrayButton)) Then _DefineTime() EndIf TrayItemSetText($TrayButton,"Stop") Global $timer = TimerInit() Global $timer2 = TimerInit() Global $Hours = GUICtrlRead($IHour) Global $Mins = GUICtrlRead($IMin) Global $Secs = GUICtrlRead($ISec) GUICtrlSetData($Ok, "Stop") ;~ $Times = StringFormat("%02i:%02i", $Mins, $Secs) ;~ ControlSetText("Timer", "" , "Static2", $Times) AdlibEnable("Timer", 1000) While ($Hours >= 0) Global $nMsg = GUIGetMsg() Test_Radio_Button() $OkValue = GUICtrlRead($Ok) Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) Case $Ok,$TrayButton If ($OkValue = "Stop") Then TrayItemSetText($TrayButton,"Continue") $HourT = $Hour $MinT = $Min $SecT = $Sec ;~ AdlibDisable() GUICtrlSetData($Ok, "Continue") ElseIf ($OkValue = "Continue") Then ;~ Global $TimePause = StringFormat("%02i:%02i:%02i", $HourT, $MinT, $SecT) ;~ ControlSetText("Timer", "" , "Static2", $TimePause) TrayItemSetText($TrayButton,"Stop") Global $timer = TimerInit() Global $Hours = GUICtrlRead($IHour) Global $Mins = GUICtrlRead($IMin) Global $Secs = GUICtrlRead($ISec) GUICtrlSetData($Ok, "Stop") AdlibEnable("Timer", 1000) EndIf EndSwitch WEnd Finish() Case $Browse $Src = FileOpenDialog ("Emplacement Musique",@MyDocumentsDir,"Musique (*.mp3;*.wav)", 1+2) If ($Src <> "") Then GUICtrlSetData($Input , $Src) $Source = $Src Else GUICtrlSetData($Input , "Default") EndIf Case $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) Case $GUI_EVENT_CLOSE Exit EndSwitch Test_Radio_Button() WEnd Func Init() Global $GUI = GUICreate("TimerOff", 410, 260, -1, -1, $WS_OVERLAPPEDWINDOW) GUICtrlSetColor(-1, 32250) WinSetTrans("TimerOff", "", 210) Global $Ok = GUICtrlCreateButton("Ok", 160, 220, 80, 35) GUICtrlCreateLabel("00:00:00", 10, 10) GUICtrlCreateLabel("Hours", 70, 30) Global $IHour = GUICtrlCreateInput("0", 70, 50, 40, 20) GUICtrlCreateUpdown(-1) GUICtrlCreateLabel("Mins", 170, 30) Global $IMin = GUICtrlCreateInput("15", 170, 50, 40, 20) GUICtrlCreateUpdown(-1) GUICtrlCreateLabel("Secs", 267, 30) Global $ISec = GUICtrlCreateInput("0", 267, 50, 40, 20) GUICtrlCreateUpdown(-1) GUICtrlCreateGroup("Turn Off Methods", 65, 85, 245, 70) Global $Shut1 = GUICtrlCreateRadio("Hibernate", 85, 105, 100) GUICtrlSetState(-1, $GUI_CHECKED) Global $Shut2 = GUICtrlCreateRadio("Standby", 85, 125, 80) Global $Shut3 = GUICtrlCreateRadio("Reboot", 205, 105, 70) Global $Shut4 = GUICtrlCreateRadio("Turn Off", 205, 125, 80) Global $Shut5 = GUICtrlCreateRadio("Alarm", 85, 179, 63) Global $Input = GUICtrlCreateInput("Default" , 150, 179, 100,22,$ES_READONLY) Global $Browse = GUICtrlCreateButton("Parcourir" , 255, 179, 50, 22) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("Other", 65, 162, 245,50) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlCreateGroup("Quick Launch", 320, 30, 85,182) Global $Go30 = GUICtrlCreateButton("30 min", 328, 65, 70, 35) Global $Go45 = GUICtrlCreateButton("45 min", 328, 115, 70, 35) Global $Go60 = GUICtrlCreateButton("1 hour", 328, 165, 70, 35) GUICtrlCreateGroup("", -99, -99, 1, 1) GUICtrlSetState($Input, $GUI_HIDE) GUICtrlSetState($Browse, $GUI_HIDE) GUICtrlSetState($Ok, $GUI_FOCUS) Global $Time, $sTime Global $OkValue = "Stop" Global $Hour, $Min, $Sec = 0 Global $ShutValue = 0 Global $TimePause = TimerInit() EndFunc ;==>Init Func Timer() _TicksToTime(Int(TimerDiff($timer2)), $HourT, $MinT, $SecT) If ($OkValue = "Stop") Then _TicksToTime(Int(TimerDiff($timer)), $Hour, $Min, $Sec) Global $sTime = $Time ; save current time to be able to test and avoid flicker.. If ($Secs < $Sec - 1) Then GUICtrlSetData($ISec, 60 + ($Secs - $Sec)) ElseIf ($Secs = $Sec - 1) Then $Mins = $Mins - 1 If (($Hours >= 0) And ($Mins > -1)) Then GUICtrlSetData($IMin, $Mins) GUICtrlSetData($ISec, 59) EndIf Else GUICtrlSetData($ISec, $Secs - $Sec) EndIf If ($Mins <= -1) Then $Hours = $Hours - 1 $Mins = 59 If ($Hours >= 0) Then GUICtrlSetData($IHour, $Hours) GUICtrlSetData($IMin, 59) EndIf EndIf EndIf $Time = StringFormat("%02i:%02i:%02i", $HourT, $MinT, $SecT) If $sTime <> $Time Then ControlSetText("Timer", "", "Static1", $Time) EndFunc ;==>Timer Func Test_Radio_Button() Select Case $nMsg = $Shut1 Or $nMsg = $Shut2 Or $nMsg = $Shut3 Or $nMsg = $Shut4 Or $nMsg = $Shut5 If ($nMsg = $Shut5) Then GUICtrlSetState($Input, $GUI_SHOW) GUICtrlSetState($Browse, $GUI_SHOW) Else GUICtrlSetState($Input, $GUI_HIDE) GUICtrlSetState($Browse, $GUI_HIDE) EndIf $ShutValue = $nMsg - $Shut1 EndSelect TrayOff() EndFunc ;==>Test_Radio_Button Func Set_Time() Switch $nMsg Case $IHour If (GUICtrlRead($IHour) < 0) Then GUICtrlSetData($IHour, 0) EndIf Case $IMin If (GUICtrlRead($IMin) >= 60) Then GUICtrlSetData($IMin, 59) EndIf If (GUICtrlRead($IMin) < 0) Then GUICtrlSetData($IMin, 0) EndIf Case $ISec If (GUICtrlRead($ISec) >= 60) Then GUICtrlSetData($ISec, 59) EndIf If (GUICtrlRead($ISec) < 0) Then GUICtrlSetData($ISec, 0) EndIf EndSwitch EndFunc ;==>Set_Time Func _DefineTime() Switch $nMsg Case $Go30 GUICtrlSetData($IHour, "0") GUICtrlSetData($IMin, "0") GUICtrlSetData($ISec, "5") Case $Go45 GUICtrlSetData($IHour, "0") GUICtrlSetData($IMin, "45") GUICtrlSetData($ISec, "0") Case $Go60 GUICtrlSetData($IHour, "1") GUICtrlSetData($IMin, "0") GUICtrlSetData($ISec, "0") EndSwitch EndFunc Func InitTray() Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) TraySetState() TraySetClick(8) TraySetIcon("ATP32.dll", -1) TraySetOnEvent($TRAY_EVENT_MOUSEOVER, "_Show") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"_ShowGUI") Global $Tray1 = TrayCreateItem(" Hibernate") TrayItemSetOnEvent(-1, "_Shut1") Global $Tray2 = TrayCreateItem(" Standby") TrayItemSetOnEvent(-1, "_Shut2") Global $Tray3 = TrayCreateItem(" Reboot") TrayItemSetOnEvent(-1, "_Shut3") Global $Tray4 = TrayCreateItem(" Turn Off") TrayItemSetOnEvent(-1, "_Shut4") Global $Tray5 = TrayCreateItem(" Alarm") TrayItemSetOnEvent(-1, "_Shut5") TrayCreateItem("") Global $TrayButton = TrayCreateItem("Go") TrayItemSetOnEvent(-1, "_TrayButton") TrayCreateItem("Resume") TrayItemSetOnEvent(-1, "_Resume") TrayCreateItem("Quitter") TrayItemSetOnEvent(-1, "_Exit") EndFunc Func _TrayButton() Global $nMsg = $TrayButton EndFunc Func _Resume() _ShowGUI() Test_Radio_Button() GUICtrlSetData($IHour, "0") GUICtrlSetData($IMin, "0") GUICtrlSetData($ISec, "0") Global $timer = TimerInit() Global $timer2 = TimerInit() AdlibEnable("Timer", 1000) Finish() EndFunc Func _Shut1() GUICtrlSetState($Shut1, $GUI_CHECKED) Global $nMsg = $Shut1 Test_Radio_Button() EndFunc Func _Shut2() GUICtrlSetState($Shut2, $GUI_CHECKED) Global $nMsg = $Shut2 Test_Radio_Button() EndFunc Func _Shut3() GUICtrlSetState($Shut3, $GUI_CHECKED) Global $nMsg = $Shut3 Test_Radio_Button() EndFunc Func _Shut4() GUICtrlSetState($Shut4, $GUI_CHECKED) Global $nMsg = $Shut4 Test_Radio_Button() EndFunc Func _Shut5() GUICtrlSetState($Shut5, $GUI_CHECKED) Global $nMsg = $Shut5 Test_Radio_Button() EndFunc Func TrayOff() Switch $ShutValue Case 0 TrayItemSetText($Tray1,">Hibernate") TrayItemSetText($Tray2," Standby") TrayItemSetText($Tray3," Reboot") TrayItemSetText($Tray4," Turn Off") TrayItemSetText($Tray5," Alarm") Case 1 TrayItemSetText($Tray1," Hibernate") TrayItemSetText($Tray2,">Standby") TrayItemSetText($Tray3," Reboot") TrayItemSetText($Tray4," Turn Off") TrayItemSetText($Tray5," Alarm") Case 2 TrayItemSetText($Tray1," Hibernate") TrayItemSetText($Tray2," Standby") TrayItemSetText($Tray3,">Reboot") TrayItemSetText($Tray4," Turn Off") TrayItemSetText($Tray5," Alarm") Case 3 TrayItemSetText($Tray1," Hibernate") TrayItemSetText($Tray2," Standby") TrayItemSetText($Tray3," Reboot") TrayItemSetText($Tray4,">Turn Off") TrayItemSetText($Tray5," Alarm") Case 4 TrayItemSetText($Tray1," Hibernate") TrayItemSetText($Tray2," Standby") TrayItemSetText($Tray3," Reboot") TrayItemSetText($Tray4," Turn Off") TrayItemSetText($Tray5,">Alarm") EndSwitch EndFunc Func _Show() $TimeT = StringFormat("Remaining %02i:%02i:%02i",GUICtrlRead($IHour), GUICtrlRead($IMin),GUICtrlRead($ISec)) TraySetToolTip($TimeT) EndFunc Func _ShowGUI() GUISetState(@SW_SHOW) GUISetState(@SW_RESTORE) EndFunc Func Finish() ;~ AdlibDisable() $OkValue = "End" If $ShutValue = 0 Then Shutdown(64) ;~ Run(@ComSpec & " /c " & "rundll32 powrprof.dll,SetSuspendState",@SW_HIDE) ElseIf $ShutValue = 1 Then Shutdown(32) ElseIf $ShutValue = 2 Then Shutdown(2) ;~ Run(@ComSpec & " /c " & "shutdown -r -f -t 0", @SW_HIDE) ElseIf $ShutValue = 3 Then Shutdown(1) ;~ Run(@ComSpec & " /c " & "shutdown -s -f -t 0", @SW_HIDE) ElseIf $ShutValue = 4 Then GUICtrlSetData($Ok,"Quitter") $Src = GUICtrlRead($Input) If ($Src = "Default") Then $Src = @TempDir & "\TimerDefault.mp3" FileInstall("C:\Documents and Settings\L!nk\Mes documents\Downloads\Lady Gaga Ft. Colby O'Donis & Akon - Just Dance.mp3", @TempDir & "\TimerDefault.mp3", 1) EndIf $Sound = _SoundOpen($Src,0) _SoundPlay($Sound) While 1 Global $nMsg = GUIGetMsg() If _SoundPos($Sound, 2) = _SoundLength($Sound, 2) Then _SoundPlay($Sound) EndIf Switch $nMsg Case $Ok ExitLoop Case $GUI_EVENT_CLOSE ExitLoop Case $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE) EndSwitch WEnd _SoundClose($Sound) EndIf FileDelete(@TempDir & "\TimerDefault.mp3") Exit EndFunc ;==>Finish Func _Exit() Exit EndFunc