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
}
32 \helpref{wxObject
}{wxobject
}
34 \wxheading{Include files
}
40 \helpref{wxBase
}{librarieslist
}
44 \helpref{wxStopWatch
}{wxstopwatch
}
46 \latexignore{\rtfignore{\wxheading{Members
}}}
48 \membersection{wxTimer::wxTimer
}\label{wxtimerwxtimer
}
50 \func{}{wxTimer
}{\void}
52 Default constructor. If you use it to construct the object and don't call
53 \helpref{SetOwner
}{wxtimersetowner
} later, you must override
54 \helpref{Notify
}{wxtimernotify
} method to process the notifications.
56 \func{}{wxTimer
}{\param{wxEvtHandler *
}{owner
},
\param{int
}{id = -
1}}
58 Creates a timer and associates it with
{\it owner
}. Please see
59 \helpref{SetOwner
}{wxtimersetowner
} for the description of parameters.
61 \membersection{wxTimer::
\destruct{wxTimer
}}\label{wxtimerdtor
}
63 \func{}{\destruct{wxTimer
}}{\void}
65 Destructor. Stops the timer if it is running.
67 \membersection{wxTimer::GetInterval
}\label{wxtimergetinterval
}
69 \constfunc{int
}{GetInterval
}{\void}
71 Returns the current interval for the timer (in milliseconds).
73 \membersection{wxTimer::GetOwner
}\label{wxtimergetowner
}
75 \constfunc{wxEvtHandler
}{GetOwner
}{\void}
77 Returns the current
{\it owner
} of the timer.
78 If non-
\NULL this is the event handler which will receive the
79 \helpref{timer events
}{wxtimerevent
} when the timer is running.
81 \membersection{wxTimer::GetId
}\label{wxtimergetid
}
83 \constfunc{int
}{GetId
}{\void}
85 Returns the ID of the events generated by this timer.
87 \membersection{wxTimer::IsOneShot
}\label{wxtimerisoneshot
}
89 \constfunc{bool
}{IsOneShot
}{\void}
91 Returns
{\tt true
} if the timer is one shot, i.e.\ if it will stop after firing the
92 first notification automatically.
94 \membersection{wxTimer::IsRunning
}\label{wxtimerisrunning
}
96 \constfunc{bool
}{IsRunning
}{\void}
98 Returns
{\tt true
} if the timer is running,
{\tt false
} if it is stopped.
100 \membersection{wxTimer::Notify
}\label{wxtimernotify
}
102 \func{void
}{Notify
}{\void}
104 This member should be overridden by the user if the default constructor was
105 used and
\helpref{SetOwner
}{wxtimersetowner
} wasn't called.
107 Perform whatever action which is to be taken periodically here.
109 \membersection{wxTimer::SetOwner
}\label{wxtimersetowner
}
111 \func{void
}{SetOwner
}{\param{wxEvtHandler *
}{owner
},
\param{int
}{id = -
1}}
113 Associates the timer with the given
{\it owner
}\/ object. When the timer is
114 running, the owner will receive
\helpref{timer events
}{wxtimerevent
} with
115 id equal to
{\it id
}\/ specified here.
117 \membersection{wxTimer::Start
}\label{wxtimerstart
}
119 \func{bool
}{Start
}{\param{int
}{milliseconds = -
1},
\param{bool
}{oneShot =
{\tt false
}}}
121 (Re)starts the timer. If
{\it milliseconds
}\/ parameter is -
1 (value by default),
122 the previous value is used. Returns
{\tt false
} if the timer could not be started,
123 {\tt true
} otherwise (in MS Windows timers are a limited resource).
125 If
{\it oneShot
}\/ is
{\tt false
} (the default), the
\helpref{Notify
}{wxtimernotify
}
126 function will be called repeatedly until the timer is stopped. If
{\tt true
},
127 it will be called only once and the timer will stop automatically. To make your
128 code more readable you may also use the following symbolic constants:
131 \begin{twocollist
}\itemsep=
0pt
132 \twocolitem{wxTIMER
\_CONTINUOUS}{Start a normal, continuously running, timer
}
133 \twocolitem{wxTIMER
\_ONE\_SHOT}{Start a one shot timer
}
136 If the timer was already running, it will be stopped by this method before
139 \membersection{wxTimer::Stop
}\label{wxtimerstop
}
141 \func{void
}{Stop
}{\void}
152 \section{\class{wxTimerEvent
}}\label{wxtimerevent
}
154 wxTimerEvent object is passed to the event handler of timer events.
159 class MyFrame : public wxFrame
163 void OnTimer(wxTimerEvent& event);
169 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
170 EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
174 : m_timer(this, TIMER_ID)
176 m_timer.Start(
1000); //
1 second interval
179 void MyFrame::OnTimer(wxTimerEvent& event)
181 // do whatever you want to do every second here
186 \wxheading{Derived from
}
188 \helpref{wxEvent
}{wxevent
}\\
189 \helpref{wxObject
}{wxobject
}
191 \wxheading{Include files
}
197 \helpref{wxBase
}{librarieslist
}
201 \helpref{wxTimer
}{wxtimer
}
203 \latexignore{\rtfignore{\wxheading{Members
}}}
205 \membersection{wxTimerEvent::GetInterval
}\label{wxtimereventgetinterval
}
207 \constfunc{int
}{GetInterval
}{\void}
209 Returns the interval of the timer which generated this event.
212 \membersection{wxTimerEvent::GetTimer
}\label{wxtimereventgettimer
}
214 \constfunc{wxTimer\&
}{GetTimer
}{\void}
216 Returns the timer object which generated this event.