#include </home/zeitlin/src/wx/github/interface/wx/timer.h>
The wxTimer class allows you to execute code at specified intervals.
Its precision is platform-dependent, but in general will not be better than 1ms
nor worse than 1s
.
There are three different ways to use this class:
EVT_TIMER
macro to connect it to the event handler which will receive wxTimerEvent notifications.EVT_TIMER
macro to connect it to an event handler defined in the derived class. If the default constructor is used, the timer object will be its own owner object, since it is derived from wxEvtHandler.In any case, you must start the timer with wxTimer::Start() after constructing it before it actually starts sending notifications. It can be stopped later with wxTimer::Stop().
Public Member Functions | |
wxTimer () | |
Default constructor. | |
wxTimer (wxEvtHandler *owner, int id=-1) | |
Creates a timer and associates it with owner. | |
virtual | ~wxTimer () |
Destructor. | |
int | GetId () const |
Returns the ID of the events generated by this timer. | |
int | GetInterval () const |
Returns the current interval for the timer (in milliseconds). | |
wxEvtHandler * | GetOwner () const |
Returns the current owner of the timer. | |
bool | IsOneShot () const |
Returns true if the timer is one shot, i.e. | |
bool | IsRunning () const |
Returns true if the timer is running, false if it is stopped. | |
virtual void | Notify () |
This member should be overridden by the user if the default constructor was used and SetOwner() wasn't called. | |
void | SetOwner (wxEvtHandler *owner, int id=-1) |
Associates the timer with the given owner object. | |
virtual bool | Start (int milliseconds=-1, bool oneShot=false) |
(Re)starts the timer. | |
virtual void | Stop () |
Stops the timer. |
wxTimer::wxTimer | ( | ) |
Default constructor.
If you use it to construct the object and don't call SetOwner() later, you must override Notify() method to process the notifications.
wxTimer::wxTimer | ( | wxEvtHandler * | owner, |
int | id = -1 |
||
) |
Creates a timer and associates it with owner.
Please see SetOwner() for the description of parameters.
virtual wxTimer::~wxTimer | ( | ) | [virtual] |
Destructor.
Stops the timer if it is running.
int wxTimer::GetId | ( | ) | const |
Returns the ID of the events generated by this timer.
int wxTimer::GetInterval | ( | ) | const |
Returns the current interval for the timer (in milliseconds).
wxEvtHandler* wxTimer::GetOwner | ( | ) | const |
Returns the current owner of the timer.
If non-NULL this is the event handler which will receive the timer events (see wxTimerEvent) when the timer is running.
bool wxTimer::IsOneShot | ( | ) | const |
Returns true if the timer is one shot, i.e.
if it will stop after firing the first notification automatically.
bool wxTimer::IsRunning | ( | ) | const |
Returns true if the timer is running, false if it is stopped.
virtual void wxTimer::Notify | ( | ) | [virtual] |
This member should be overridden by the user if the default constructor was used and SetOwner() wasn't called.
Perform whatever action which is to be taken periodically here.
Notice that throwing exceptions from this method is currently not supported, use event-based timer handling approach if an exception can be thrown while handling timer notifications.
void wxTimer::SetOwner | ( | wxEvtHandler * | owner, |
int | id = -1 |
||
) |
Associates the timer with the given owner object.
When the timer is running, the owner will receive timer events (see wxTimerEvent) with id equal to id specified here.
virtual bool wxTimer::Start | ( | int | milliseconds = -1 , |
bool | oneShot = false |
||
) | [virtual] |
(Re)starts the timer.
If milliseconds parameter is -1 (value by default), the previous value is used. Returns false if the timer could not be started, true otherwise (in MS Windows timers are a limited resource).
If oneShot is false (the default), the Notify() function will be called repeatedly until the timer is stopped. If true, it will be called only once and the timer will stop automatically.
To make your code more readable you may also use the following symbolic constants:
virtual void wxTimer::Stop | ( | ) | [virtual] |
Stops the timer.