If you can check it out, tell me what you think :)
*updated*
I fixed some stuff that were wrong and causing extreme cpu usage and added a few functions to make it a bit better. (like, check if the user entered a valid time)
It also can display a personal message or reminder at the time you say.
Thanks to bogQ and Generator who gave me a hand with some important details.
Now, this program is perfect.
#include <GuiConstants.au3> ;============================= ;Author: Nahuel Jose ;Language: AutoIT ;email:nahueljose@gmail.com ;============================= #include <GuiConstants.au3> $loop2=1 $AnchoVentana = 250 $AltoVentana = 200 $MargenIzquierdo=10 $MargenSuperior=10 $Separador=20 $AnchoEtiqueta=130 $AltoEtiqueta=22 Opt("TrayAutoPause",0) Opt("TrayMenuMode",1) GuiCreate("Timer", $AnchoVentana, $AltoVentana) ;Current time: $Reloj=GUICtrlCreateLabel(@HOUR&":"&@MIN,$AnchoVentana/2-$Separador,$MargenSuperior+6,$AnchoEtiqueta) GUICtrlSetFont($Reloj, 10, 500, "", "Verdana") ;Hour $HoraApagado = GUICtrlCreateInput (@HOUR,$MargenIzquierdo+5,$MargenSuperior+$Separador*2+10, 60, 20,$ES_READONLY) GUICtrlCreateUpdown($HoraApagado) GUICtrlSetLimit(-1, 23,00) GUICtrlSetLimit($HoraApagado, 2) GUICtrlCreateLabel("Hours",$MargenIzquierdo+5+65,$MargenSuperior+$Separador*2+12) ;Minutes $MinApagado = GUICtrlCreateInput (@MIN,$MargenIzquierdo+$Separador+100,$MargenSuperior+$Separador*2+10, 60, 20,$ES_READONLY) GUICtrlCreateUpdown($MinApagado) GUICtrlSetLimit(-1, 59,00) GUICtrlSetLimit($MinApagado, 2) GUICtrlCreateLabel("Minutes",$MargenIzquierdo+$Separador+100+65,$MargenSuperior+$Separador*2+12) ;Events $combo=GUICtrlCreateCombo("Shutdown",$MargenIzquierdo+5,$MargenSuperior+$Separador*4+25,220,200,$WS_VSCROLL+$CBS_DROPDOWNLIST+$CBS_AUTOHSCROLL) GUICtrlSetData($combo,"Reboot|Logoff|Display Message","Apagar") ;Groups GUICtrlCreateGroup("Current Time:",$MargenIzquierdo-5,$MargenSuperior-5,$AnchoVentana-10,$AltoEtiqueta+10) GUICtrlCreateGroup("Time of Event:", $MargenIzquierdo-5, $MargenSuperior+$Separador+10,$AnchoVentana-10,$AltoEtiqueta+10+$Separador) GUICtrlCreateGroup("Event:",$MargenIzquierdo-5,$MargenSuperior+$Separador*4+6,$AnchoVentana-10, $AltoEtiqueta+10+$Separador) ;Buttons $Aplicar=GUICtrlCreateButton("&Apply",$MargenIzquierdo+10,$MargenSuperior+$Separador*7+15,100,-1,$BS_DEFPUSHBUTTON) $Cancelar=GUICtrlCreateButton("&Cancel",$MargenIzquierdo+$Separador+105,$MargenSuperior+$Separador*7+15,100) ;Tray icon menu Opt("TrayOnEventMode",1) TrayCreateItem("About") TrayItemSetOnEvent(-1, "about") TrayCreateItem("") TrayCreateItem("New event") TrayItemSetOnEvent(-1, "nueva_hora") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "app_close") TraySetToolTip("Currently Idle") GUISetState() $MediElTiempo=False $loop = 0 While $loop = 0 ;========================= ;Refreshes current time every 4 seconds. if Not $MediElTiempo Then $Empezar = TimerInit() $MediElTiempo = True EndIf $dif = TimerDiff($Empezar) if $dif>4000 Then refrescar_reloj() $MediElTiempo = False EndIf ;========================= $msg=GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $loop=1 Case $msg = $Aplicar ;========================================== ;Checks if the entered numbers have two digits. If they don't, it adds a 0. $largo1=StringLen(GUICtrlRead($HoraApagado)) If $largo1<2 Then GUICtrlSetData($HoraApagado,"0"&GUICtrlRead($HoraApagado)) EndIf $largo2=StringLen(GUICtrlRead($MinApagado)) If $largo2<2 Then GUICtrlSetData($MinApagado,"0"&GUICtrlRead($MinApagado)) EndIf ;============================================ If GUICtrlRead($combo)="Display Message" Then $Mensaje=InputBox("Message","Type the message that you would like to display at the selected time") If @error<>1 Then funcionar() Else EndIf Else funcionar() EndIf Case $msg=$Cancelar $loop=1 EndSelect WEnd Func refrescar_reloj() GUICtrlSetData($Reloj,@HOUR&":"&@MIN) EndFunc Func about() MsgBox(0,"About","Author: Nahuel José"&@CRLF&"E-mail: nahueljose@gmail.com"&@CRLF&@CRLF&"Language:AutoIt"&@CRLF&"www.autoitscript.com") EndFunc Func app_close() Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(52,"Exit","Really quit?") Select Case $iMsgBoxAnswer = 6 ;Yes Exit Case $iMsgBoxAnswer = 7 ;No EndSelect EndFunc Func nueva_hora() If $loop2=0 Then Dim $iMsgBoxAnswer2 $iMsgBoxAnswer2 = MsgBox(36,"New Event","Restart timer and select new time and event?") Select Case $iMsgBoxAnswer2 = 6 ;Yes $loop2=1 GUISetState(@SW_SHOW) TraySetToolTip("Currently Idle") Case $iMsgBoxAnswer2 = 7 ;No EndSelect Else $loop2=1 GUISetState(@SW_SHOW) TraySetToolTip("Currently Idle") EndIf EndFunc Func apagar() ProcessClose("explorer.exe") Shutdown(9);Shutdown EndFunc Func reiniciar() ProcessClose("explorer.exe") Shutdown(2);Reboot EndFunc Func cerrar_sesion() Shutdown(0);Logoff EndFunc Func funcionar() TraySetToolTip("Event: "&GUICtrlRead($combo)&". Time of Event: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado)) MsgBox(0,Guictrlread($combo),"Time for selected event: "&GUICtrlRead($HoraApagado)&":"&GUICtrlRead($MinApagado)) GUISetState(@SW_HIDE) $loop2=0 $MediElTiempo1=False While $loop2=0 If @HOUR=GUICtrlRead($HoraApagado) And @MIN=GUICtrlRead($MinApagado) Then Select ;SHUTDOWN Case GUICtrlRead($combo)="Shutdown" Dim $iMsgBoxAnswer3 $iMsgBoxAnswer3 = MsgBox(49,"Shutdown","Will shutdown in 5 seconds",5) Select Case $iMsgBoxAnswer3 = 1 ;Yes apagar() Case $iMsgBoxAnswer3 = 2 ;No Exit Case $iMsgBoxAnswer3 = -1;TimeOut apagar() Exit EndSelect ;REBOOT Case GUICtrlRead($combo)="Reboot" Dim $iMsgBoxAnswer4 $iMsgBoxAnswer4 = MsgBox(49,"Reboot","Will reboot in 5 seconds",5) Select Case $iMsgBoxAnswer4 = 1 ;Yes reiniciar() Case $iMsgBoxAnswer4 = 2 ;No Exit Case $iMsgBoxAnswer4 = -1;TimeOut reiniciar() EndSelect ;LOGOFF Case GUICtrlRead($combo)="LOGOFF" Dim $iMsgBoxAnswer5 $iMsgBoxAnswer5 = MsgBox(49,"LOGOFF","Will logoff in 5 seconds",5) Select Case $iMsgBoxAnswer5 = 1 ;Yes cerrar_sesion() Exit Case $iMsgBoxAnswer5 = 2 ;No Exit Case $iMsgBoxAnswer5 = -1;TimeOut cerrar_sesion() Exit EndSelect Case GUICtrlRead($combo)="Display Message" SoundPlay(@windowsdir&"\media\tada.wav") MsgBox(0,"Message!",$Mensaje) Exit EndSelect EndIf WEnd EndFunc
Download Shutdown/Reboot/Logoff Timer - Compiled
This post has been edited by Nahuel: 13 August 2007 - 04:02 AM

Sign In
Register
Help


MultiQuote