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::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: