somdcomputerguy Posted June 2, 2010 Posted June 2, 2010 (edited) This is a basically just a countdown script, that I wrote for one particular situation and I didn't feel like downloading a timer program. What was once less than 10 lines of code is now more than 200 and has ended up being used almost daily. The code isn't commented at all, but it should be pretty easy to understand, and maybe it would help someone, so of course I would answer any questions that would arise. Or maybe someone could actually use this for something. expandcollapse popup#include <Date.au3> #include <Constants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("TrayMenuMode", 3) Opt("GUIOnEventMode", 1) Opt("TrayOnEventMode", 1) Opt('MustDeclareVars', 1) Local $Form, $Checkbox_Repeat, $Input_Message, $Input_HrMin, $Input_SpecificTime, $Combo_TimeFrame, $Button_Start, $TrayToggleHide, $TrayRestart, $TrayExit, $AdlibToolTip Global $JAIni = @ScriptDir & "\JATimer.ini" #Region ### START GUI section ### $Form = GUICreate("JATimer", 420, 35, -1, 380, $WS_POPUP) GUISetFont(11, 400, Default, "Comic Sans MS") GUISetBkColor(0x252525) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") GUISetIcon("Clock.ico") _GuiRoundCorners($Form, 0, 0, 25, 25) $Input_Message = GUICtrlCreateInput("Message Text", 20, 5, 130, 25, $ES_CENTER) $Combo_TimeFrame = GUICtrlCreateCombo("Time Frame", 155, 5, 105, 20) GUICtrlSetData($Combo_TimeFrame, "Hour.Hr|Hour,Min|Minute|Time|Test") GUICtrlSetOnEvent($Combo_TimeFrame, "CheckCombo") $Input_HrMin = GUICtrlCreateInput("", 265, 5, 55, 25, $ES_CENTER) GUICtrlSetState($Input_HrMin, $GUI_DISABLE) $Input_SpecificTime = GUICtrlCreateInput(@HOUR & ":" & @MIN, 265, 5, 55, 25, $ES_CENTER) GUICtrlSetState($Input_SpecificTime, $GUI_DISABLE) $Button_Start = GUICtrlCreateButton("Start", 325, 5, 75, 25, $WS_GROUP) GUICtrlSetOnEvent($Button_Start, "ScheduledWait") GUISetState(@SW_SHOW) #EndRegion ### END GUI section ### #Region ### START Tray section ### $TrayToggleHide = TrayCreateItem("Show/Hide") TrayItemSetOnEvent($TrayToggleHide, "ToggleHide") $TrayRestart = TrayCreateItem("Restart") TrayItemSetOnEvent($TrayRestart, "Restart") $TrayExit = TrayCreateItem("Exit") TrayItemSetOnEvent($TrayExit, "Quit") TraySetState() TraySetClick(9) TraySetIcon(@ScriptDir & "\Clock.ico") TraySetToolTip(" JATimer - Click here for the menu. ") TraySetOnEvent($TRAY_EVENT_MOUSEOVER,"MouseOverTray") #EndRegion ### END Tray section ### If FileExists($JAIni) Then ControlSetText("JATimer", "", "Edit1", IniRead($JAIni, "Text Message", "message", "Message Text")) ControlCommand("JATimer", "", "ComboBox1", "SetCurrentSelection", IniRead($JAIni, "ComboBox", "cursel", 0)) FileDelete($JAIni) EndIf While 1 Sleep(10) WEnd Func ScheduledWait() ToolTip("") ;GUICtrlSetState($Input_Message, $GUI_FOCUS) If GUICtrlRead($Combo_TimeFrame) = "Time Frame" Then MsgBox(16, StringTrimRight(@Scriptname, 4) & " Error", "You must select a time frame..", 3) If GUICtrlRead($Input_Message) <> "Message Text" Or GUICtrlRead($Input_Message) <> "" Then IniWrite($JAIni, "Text Message", "message", GUICtrlRead($Input_Message)) EndIf Restart() EndIf If GUICtrlRead($Combo_TimeFrame) = "Hour.Hr" And StringInStr(GUICtrlRead($Input_HrMin), ",") Then MsgBox(16, StringTrimRight(@Scriptname, 4) & " Error", "The Hour.Hr Time Frame can't have a comma", 3) If GUICtrlRead($Input_Message) <> "Message Text" Or GUICtrlRead($Input_Message) <> "" Then IniWrite($JAIni, "ComboBox", "cursel", "1") IniWrite($JAIni, "Text Message", "message", GUICtrlRead($Input_Message)) EndIf Restart() EndIf If GUICtrlRead($Combo_TimeFrame) = "Hour,Min" And StringInStr(GUICtrlRead($Input_HrMin), ".") Then MsgBox(16, StringTrimRight(@Scriptname, 4) & " Error", "The Hour,Min Time Frame can't have a period", 3) If GUICtrlRead($Input_Message) <> "Message Text" Or GUICtrlRead($Input_Message) <> "" Then IniWrite($JAIni, "ComboBox", "cursel", "2") IniWrite($JAIni, "Text Message", "message", GUICtrlRead($Input_Message)) EndIf Restart() EndIf If GUICtrlRead($Combo_TimeFrame) = "Minute" And StringInStr(GUICtrlRead($Input_HrMin), ",") Then MsgBox(16, StringTrimRight(@Scriptname, 4) & " Error", "The Minute Time Frame can't have a comma", 3) If GUICtrlRead($Input_Message) <> "Message Text" Or GUICtrlRead($Input_Message) <> "" Then IniWrite($JAIni, "ComboBox", "cursel", "3") IniWrite($JAIni, "Text Message", "message", GUICtrlRead($Input_Message)) EndIf Restart() EndIf GUICtrlSetData($Button_Start, "Tick Tock") GUICtrlSetState($Input_Message, $GUI_DISABLE) GUICtrlSetState($Combo_TimeFrame, $GUI_DISABLE) GUICtrlSetState($Input_HrMin, $GUI_DISABLE) GUICtrlSetState($Input_SpecificTime, $GUI_DISABLE) For $transvalue = 250 To 5 Step -5 WinSetTrans("JATimer", "", $transvalue) Sleep(10) Next WinSetState("JATimer", "", @SW_HIDE) WinSetTrans("JATimer", "", 255) Local $DecimalPosition, $TimeFraction1, $TimeFraction2, $CountdownToDate Switch GUICtrlRead($Combo_TimeFrame) Case "Hour.Hr" If StringInStr(GUICtrlRead($Input_HrMin), ".") Then $DecimalPosition = StringInStr(GUICtrlRead($Input_HrMin), ".") $TimeFraction1 = StringSplit(GUICtrlRead($Input_HrMin), ".") $TimeFraction2 = StringMid(GUICtrlRead($Input_HrMin), $DecimalPosition) $CountdownToDate = _DateAdd('n', (60 * $TimeFraction1[1]) + (60 * $TimeFraction2), _NowCalc()) Else $CountdownToDate = _DateAdd('h', GUICtrlRead($Input_HrMin), _NowCalc()) EndIf Case "Hour,Min" If StringInStr(GUICtrlRead($Input_HrMin), ",") Then $DecimalPosition = StringInStr(GUICtrlRead($Input_HrMin), ",") $TimeFraction1 = StringSplit(GUICtrlRead($Input_HrMin), ",") $TimeFraction2 = StringMid(GUICtrlRead($Input_HrMin), $DecimalPosition) $CountdownToDate = _DateAdd('n', (60 * $TimeFraction1[1]) + $TimeFraction1[2], _NowCalc()) Else $CountdownToDate = _DateAdd('h', GUICtrlRead($Input_HrMin), _NowCalc()) EndIf Case "Minute" If StringInStr(GUICtrlRead($Input_HrMin), ".") Then $DecimalPosition = StringInStr(GUICtrlRead($Input_HrMin), ".") $TimeFraction1 = StringSplit(GUICtrlRead($Input_HrMin), ".") $TimeFraction2 = StringMid(GUICtrlRead($Input_HrMin), $DecimalPosition) $CountdownToDate = _DateAdd('s', (60 * $TimeFraction1[1]) + (60 * $TimeFraction2), _NowCalc()) TraySetToolTip(" " & GUICtrlRead($Input_Message) & " at " & StringTrimLeft($CountdownToDate, 11) & " ") GUICtrlSetData($Input_HrMin, StringTrimRight(StringTrimLeft($CountdownToDate, 11), 3)) ;MsgBox(0, "", StringTrimLeft(_NowCalc(), 11) & @LF & " + " & (60 * $TimeFraction1[1]) + (60 * $TimeFraction2) & " seconds" & @LF & StringTrimLeft($CountdownToDate, 11)) Do Sleep(10) Until StringTrimLeft($CountdownToDate, 11) = @HOUR & ":" & @MIN & ":" & @SEC Actions() Else $CountdownToDate = _DateAdd('n', GUICtrlRead($Input_HrMin), _NowCalc()) ;MsgBox(0, "", StringTrimLeft(_NowCalc(), 11) & @LF & " + " & GUICtrlRead($Input_HrMin) & " minutes" & @LF & StringTrimLeft($CountdownToDate, 11)) EndIf Case "Time" TraySetToolTip(" " & GUICtrlRead($Input_Message) & " at " & GUICtrlRead($Input_SpecificTime) & " ") Do Sleep(10) Until GUICtrlRead($Input_SpecificTime) = @HOUR & ":" & @MIN Actions() EndSwitch If GUICtrlRead($Combo_TimeFrame) <> "Time" Or GUICtrlRead($Combo_TimeFrame) <> "Time Frame" Then TraySetToolTip(" " & GUICtrlRead($Input_Message) & " at " & StringTrimRight(StringTrimLeft($CountdownToDate, 11), 3) & " ") GUICtrlSetData($Input_HrMin, StringTrimRight(StringTrimLeft($CountdownToDate, 11), 3)) Do Sleep(10) Until StringTrimRight(StringTrimLeft($CountdownToDate, 11), 3) = @HOUR & ":" & @MIN EndIf Actions() EndFunc ;==>ScheduledWait Func Actions() If @HotKeyPressed = "{END}" Then HotKeySet("{END}") SplashOff() ;Quit() Restart() EndIf HotKeySet("{END}", "Actions") SplashTextOn("JATimer", GUICtrlRead($Input_Message), 425, 100, -1, -1, 32, "", 18) For $c = 3 To 1 Step -1 ControlSetText("", GUICtrlRead($Input_Message), "Static1", GUICtrlRead($Input_Message) & " {" & $c & "}") Beep(420, 350) Sleep(450) Next While 1 SplashOff() Sleep(500) SplashTextOn("Press 'End' to close this message", GUICtrlRead($Input_Message), 425, 100, -1, -1, 32, "", 18) Sleep(1500) WEnd EndFunc ;==>Actions Func CheckCombo() If GUICtrlRead($Combo_TimeFrame) = "Time" Then ToolTip("") GUICtrlSetState($Input_HrMin, $GUI_DISABLE + $GUI_HIDE) GUICtrlSetState($Input_SpecificTime, $GUI_ENABLE + $GUI_SHOW + $GUI_FOCUS) Else GUICtrlSetState($Input_SpecificTime, $GUI_DISABLE + $GUI_HIDE) GUICtrlSetState($Input_HrMin, $GUI_ENABLE + $GUI_SHOW + $GUI_FOCUS) Switch GUICtrlRead($Combo_TimeFrame) Case "Hour.Hr" GUICtrlSetData($Input_HrMin, "4.25") ToolTip(" 1.5 = 1 Hour and 30 Minutes ") Case "Hour,Min" GUICtrlSetData($Input_HrMin, "4,20") ToolTip(" 1,5 = 1 Hour and 5 Minutes ") Case "Minute" GUICtrlSetData($Input_HrMin, "4.25") ToolTip(" 1.5 = 1 minute and 30 seconds ") Case "Test" Local $size = WinGetPos("JATimer") WinMove("JATimer", "", Default, Default, $size[2], $size[3] + 45) _GuiRoundCorners($Form, 0, 0, 25, 25) EndSwitch EndIf If GUICtrlRead($Combo_TimeFrame) = "Time Frame" Then ToolTip("") GUICtrlSetState($Input_HrMin, $GUI_DISABLE) GUICtrlSetState($Input_SpecificTime, $GUI_DISABLE) EndIf EndFunc ;==>CheckCombo Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3) ; Round GUI Corners - http://www.autoitscript.com/forum/index.php?s=&showtopic=19370&view=findpost&p=191072 ; Author - gafrost Dim $pos, $ret, $ret2 $pos = WinGetPos($h_win) $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3, "long", $i_y3) If $ret[0] Then $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1) If $ret2[0] Then Return 1 Else Return 0 EndIf Else Return 0 EndIf DllClose($ret) DllClose($ret2) EndFunc ;==>_GuiRoundCorners Func MouseOverTray() If BitAND(WinGetState("JATimer", ""), 2) Then TrayItemSetText($TrayToggleHide, "Hide JATimer Window") Else TrayItemSetText($TrayToggleHide, "Show JATimer Window") EndIf EndFunc Func ToggleHide() If BitAND(WinGetState("JATimer", ""), 2) Then WinSetState("JATimer", "", @SW_HIDE) Else WinSetState("JATimer", "", @SW_SHOW) EndIf EndFunc ;==>ToggleHide Func Restart() ; Re-Start your Program - http://www.autoitscript.com/forum/index.php?s=&showtopic=19370&view=findpost&p=199608 ; Author UP_NORTH If @Compiled = 1 Then Run( FileGetShortName(@ScriptFullPath)) Else Run( FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath)) EndIf Exit EndFunc Func Quit() Exit EndFunc ;==>Quit ;==>Quit Edited July 1, 2010 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now