1 \section{\class{wxTimer
}}\label{wxtimer
}
3 The wxTimer class allows you to execute code at specified intervals. Its
4 precision is platform-dependent, but in general will not be better than
1ms nor
7 There are three different ways to use this class:
10 \item You may derive a new class from wxTimer and override the
11 \helpref{Notify
}{wxtimernotify
} member to perform the required action.
12 \item Or you may redirect the notifications to any
13 \helpref{wxEvtHandler
}{wxevthandler
} derived object by using the non default
14 constructor or
\helpref{SetOwner
}{wxtimersetowner
}. Then use the
{\tt EVT
\_TIMER}
15 macro to connect it to the event handler which will receive
16 \helpref{wxTimerEvent
}{wxtimerevent
} notifications.
17 \item Or you may use a derived class and the
{\tt EVT
\_TIMER}
18 macro to connect it to an event handler defined in the derived class.
19 If the default constructor is used, the timer object will be its
20 own owner object, since it is derived from wxEvtHandler.
23 In any case, you must start the timer with
\helpref{Start
}{wxtimerstart
}
24 after constructing it before it actually starts sending notifications. It can
25 be stopped later with
\helpref{Stop
}{wxtimerstop
}.
27 {\bf Note:
} A timer can only be used from the main thread.
29 \wxheading{Derived from
}
31 \helpref{wxEvtHandler
}{wxevthandler
}
33 \wxheading{Include files
}
39 \helpref{::wxStartTimer
}{wxstarttimer
},
\helpref{::wxGetElapsedTime
}{wxgetelapsedtime
},
\helpref{wxStopWatch
}{wxstopwatch
}
41 \latexignore{\rtfignore{\wxheading{Members
}}}
43 \membersection{wxTimer::wxTimer
}\label{wxtimerwxtimer
}
45 \func{}{wxTimer
}{\void}
47 Default constructor. If you use it to construct the object and don't call
48 \helpref{SetOwner
}{wxtimersetowner
} later, you must override
49 \helpref{Notify
}{wxtimernotify
} method to process the notifications.
51 \func{}{wxTimer
}{\param{wxEvtHandler *
}{owner
},
\param{int
}{id = -
1}}
53 Creates a timer and associates it with
{\it owner
}. Please see
54 \helpref{SetOwner
}{wxtimersetowner
} for the description of parameters.
56 \membersection{wxTimer::
\destruct{wxTimer
}}\label{wxtimerdtor
}
58 \func{}{\destruct{wxTimer
}}{\void}
60 Destructor. Stops the timer if it is running.
62 \membersection{wxTimer::GetInterval
}\label{wxtimergetinterval
}
64 \constfunc{int
}{GetInterval
}{\void}
66 Returns the current interval for the timer (in milliseconds).
68 \membersection{wxTimer::IsOneShot
}\label{wxtimerisoneshot
}
70 \constfunc{bool
}{IsOneShot
}{\void}
72 Returns
{\tt true
} if the timer is one shot, i.e.\ if it will stop after firing the
73 first notification automatically.
75 \membersection{wxTimer::IsRunning
}\label{wxtimerisrunning
}
77 \constfunc{bool
}{IsRunning
}{\void}
79 Returns
{\tt true
} if the timer is running,
{\tt false
} if it is stopped.
81 \membersection{wxTimer::Notify
}\label{wxtimernotify
}
83 \func{void
}{Notify
}{\void}
85 This member should be overridden by the user if the default constructor was
86 used and
\helpref{SetOwner
}{wxtimersetowner
} wasn't called.
88 Perform whatever action which is to be taken periodically here.
90 \membersection{wxTimer::SetOwner
}\label{wxtimersetowner
}
92 \func{void
}{SetOwner
}{\param{wxEvtHandler *
}{owner
},
\param{int
}{id = -
1}}
94 Associates the timer with the given
{\it owner
}\/ object. When the timer is
95 running, the owner will receive
\helpref{timer events
}{wxtimerevent
} with
96 id equal to
{\it id
}\/ specified here.
98 \membersection{wxTimer::Start
}\label{wxtimerstart
}
100 \func{bool
}{Start
}{\param{int
}{milliseconds = -
1},
\param{bool
}{oneShot =
{\tt false
}}}
102 (Re)starts the timer. If
{\it milliseconds
}\/ parameter is -
1 (value by default),
103 the previous value is used. Returns
{\tt false
} if the timer could not be started,
104 {\tt true
} otherwise (in MS Windows timers are a limited resource).
106 If
{\it oneShot
}\/ is
{\tt false
} (the default), the
\helpref{Notify
}{wxtimernotify
}
107 function will be called repeatedly until the timer is stopped. If
{\tt true
},
108 it will be called only once and the timer will stop automatically. To make your
109 code more readable you may also use the following symbolic constants:
112 \begin{twocollist
}\itemsep=
0pt
113 \twocolitem{wxTIMER
\_CONTINUOUS}{Start a normal, continuously running, timer
}
114 \twocolitem{wxTIMER
\_ONE\_SHOT}{Start a one shot timer
}
117 If the timer was already running, it will be stopped by this method before
120 \membersection{wxTimer::Stop
}\label{wxtimerstop
}
122 \func{void
}{Stop
}{\void}
126 \section{\class{wxTimerEvent
}}\label{wxtimerevent
}
128 wxTimerEvent object is passed to the event handler of timer events.
133 class MyFrame : public wxFrame
137 void OnTimer(wxTimerEvent& event);
143 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
144 EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
148 : m_timer(this, TIMER_ID)
150 m_timer.Start(
1000); //
1 second interval
153 void MyFrame::OnTimer(wxTimerEvent& event)
155 // do whatever you want to do every second here
160 \wxheading{Include files
}
166 \helpref{wxTimer
}{wxtimer
}
168 \latexignore{\rtfignore{\wxheading{Members
}}}
170 \membersection{wxTimerEvent::GetInterval
}\label{wxtimereventgetinterval
}
172 \constfunc{int
}{GetInterval
}{\void}
174 Returns the interval of the timer which generated this event.