Requirements:
You need to use tomato time management. There is no timer as mentioned in this Article, so it is easy to use a mobile phone, because it is often used before the computer to work and learn. What about the next software? There is a PomoTime that includes both the timer function and the function of adding Todolist and counting the Tomato time of the day. I only need a timer function, because Todolist still needs to be recorded in the form of paper and pen. In the past, I tried to check the time in the lower right corner of the desktop and determined whether a tomato time was over. I found that I often forgot to check the time because I was too concentrated or distracted to browse the webpage, at the same time, I want to apply what I have learned. So I thought of this method and wrote a simple timer myself.
Function Description:
1. Display minute, second, at the top of the desktop;
2. Set the minute and second;
3. A dialog box is displayed to remind you of the time consumption;
(There is no sound reminder here because this method will affect others' work and study .)
Language selection:
As this is just a very simple function implementation, there is no great requirement for the language, select C ++, the Library is wxWidget.
Interface Design:
WxFormBuilder
Key Point description:
How does one countdown to problems encountered throughout the process? The first thing that comes to mind is a similar feature like onTimer. The wxTimer class with this feature is found in the wxWidget library. in the manual, its precision is platform-dependent, but in general will not be better than 1 ms nor worse than 1 s. that is to say, the time setting using this method may cause an error of 1 mS-1 s every time. This error is not very large and has no significant impact on the overall design purpose.
All source code is in Simple timer source code
The time processing code is as follows:
1: // timer_app.h
2: //////////////////////////////////////// ////////////////////////////////////////
3: // main application frame declaration
4: //////////////////////////////////////// ////////////////////////////////////////
5:
6: class TimerFrame: public MainDialogBase
7 :{
8: public:
9: TimerFrame (wxWindow * parent );
10: virtual ~ TimerFrame ();
11:
12: protected:
13: // protected event handlers
14: virtual void OnCloseDialog (wxCloseEvent & event );
15: virtual void OnSetButtonClick (wxCommandEvent & event );
16: virtual void OnStartButtonClick (wxCommandEvent & event );
17:
18: public:
19: void OnTimer (wxTimerEvent & event );
20:
21: private:
22: int m_minute;
23: int m_second;
24: wxTimer * m_clock;
25: wxDECLARE_EVENT_TABLE ();
26 :};
27:
28: // timer_app.cpp
29: // event list, combine timer event with OnTimer function
30: wxBEGIN_EVENT_TABLE (TimerFrame, MainDialogBase)
31: EVT_TIMER (TIMER_ID, TimerFrame: OnTimer)
32: wxEND_EVENT_TABLE ()
33:
34: // ...... some code ......
35:
36: TimerFrame (wxWindow * parent): MainDialogBase (parent)
37 :{
38: m_clock = new wxTimer (); // create a new wxTimer
39: m_clock-> SetOwner (this, TIMER_ID); // set owner, # define TIMER_ID 1000
40: m_minute = 25;
41: m_second = 0;
42 :}
43:
44: // ...... some code ......
45:
46: // count down the time and show
47: void TimerFrame: OnTimer (wxTimerEvent & event)
48 :{
49: // determine the minute and second wait to show
50: if (m_second = 0 & m_minute = 0 ){
51: m_clock-> Stop ();
52: wxMessageBox (wxT ("Time over"), wxT ("Timer "));
53: return;
54:} else if (m_second = 0 ){
55: m_second = 59;
56: m_minute-= 1;
57:} else {
58: m_second-= 1;
59 :}
60: wxString sTmp;
61: sTmp. Printf (wxT ("% d"), m_minute );
62: m_minuteTextCtrl-> SetValue (sTmp );
63: sTmp. Printf (wxT ("% d"), m_second );
64: m_secondTextCtrl-> SetValue (sTmp );
65 :}
66:
Author: Zhong xiwei