czhe Posted February 20, 2010 Posted February 20, 2010 Hi all, I want to implement a timer GUI that can do the following: 1) start button that starts counting 2) stop button that stops counting 3) reset button that resets timer to zero 4) display of current count which updates every second (format: 4 hr 23 min 50 sec) Unfortunately I have no experience in creating a GUI. In fact I'm quite new to AutoIt. Can anyone give me any pointers on how to create such an application? If there are good documentations or reference scripts that I can use, please point them out. Much thanks, czhe
Moderators Melba23 Posted February 20, 2010 Moderators Posted February 20, 2010 czhe, Here is a script I wrote a long time ago for someone else. It does not do everything you want, but it should give you some good pointers for your own code: expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <Date.au3> GUICreate("Timer Test", 200, 200) $hLabel1 = GUICtrlCreateLabel("00:00:00", 20, 20, 100, 20) $hLabel2 = GUICtrlCreateLabel("", 20, 20, 100, 20) GUICtrlSetState(-1, $GUI_HIDE) $hButton = GUICtrlCreateButton("Start", 20, 100, 80, 30) $hHour = GUICtrlCreateInput("", 20, 150, 20, 20) GUICtrlSetLimit(-1, 2) $hMins = GUICtrlCreateInput("", 50, 150, 20, 20) GUICtrlSetLimit(-1, 2) $hSecs = GUICtrlCreateInput("", 80, 150, 20, 20) GUICtrlSetLimit(-1, 2) GUISetState() Global $fTimer = False Global $iEndTicks = 0 $iCurrSec = 0 While 1 Select Case @SEC <> $iCurrSec GUICtrlSetData($hLabel2, @HOUR & ":" & @MIN & ":" & @SEC) $iCurrSec = @SEC Case _TimeToTicks(@HOUR, @MIN, @SEC) = $iEndTicks GUICtrlSetData($hButton, "Start") GUICtrlSetState($hLabel2, $GUI_HIDE) For $i = $hHour To $hSecs GUICtrlSetData($i, "") Next MsgBox(0, "Timer test", "Ding!") EndSelect Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton $fTimer = Not $fTimer If $fTimer Then GUICtrlSetData($hButton, "Stop") GUICtrlSetState($hLabel2, $GUI_SHOW) Set_Alarm() Else GUICtrlSetData($hButton, "Start") GUICtrlSetState($hLabel2, $GUI_HIDE) EndIf EndSwitch WEnd Func Set_Alarm() $sAlarm_Hour = GUICtrlRead($hHour) If $sAlarm_Hour > 23 Or $sAlarm_Hour = "" Then $sAlarm_Hour = 0 GUICtrlSetData($hHour, "00") EndIf $sAlarm_Min = GUICtrlRead($hMins) If $sAlarm_Min > 59 Or $sAlarm_Min = "" Then $sAlarm_Min = 0 GUICtrlSetData($hMins, "00") EndIf $sAlarm_Sec = GUICtrlRead($hSecs) If $sAlarm_Sec > 59 Or $sAlarm_Sec = "" Then $sAlarm_Sec = 0 GUICtrlSetData($hSecs, "00") EndIf $iEndTicks = _TimeToTicks($sAlarm_Hour, $sAlarm_Min, $sAlarm_Sec) EndFunc ;==>Set_Alarm Please ask if anything is not clear in the code. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
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