contents up previous next

wxtimer

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:

  1. you may derive a new class from wxtimer and override the notify member to perform the required action.
  2. or you may redirect the notifications to any wxevthandler derived object by using the non-default constructor or setowner. then use the evt_timer macro to connect it to the event handler which will receive wxtimerevent notifications.
  3. or you may use a derived class and the 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 start after constructing it before it actually starts sending notifications. it can be stopped later with stop.

note: a timer can only be used from the main thread.

derived from

wxevthandler wxobject

include files

<wx/timer.h>

see also

::wxstarttimer, ::wxgetelapsedtime, wxstopwatch

members

wxtimer::wxtimer
wxtimer::~wxtimer
wxtimer::getinterval
wxtimer::isoneshot
wxtimer::isrunning
wxtimer::notify
wxtimer::setowner
wxtimer::start
wxtimer::stop


wxtimer::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(wxevthandler *owner, int id = -1)

creates a timer and associates it with owner. please see setowner for the description of parameters.


wxtimer::~wxtimer

~wxtimer()

destructor. stops the timer if it is running.


wxtimer::getinterval

int getinterval() const

returns the current interval for the timer (in milliseconds).


wxtimer::isoneshot

bool isoneshot() const

returns true if the timer is one shot, i.e. if it will stop after firing the first notification automatically.


wxtimer::isrunning

bool isrunning() const

returns true if the timer is running, false if it is stopped.


wxtimer::notify

void notify()

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.


wxtimer::setowner

void 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 with id equal to id specified here.


wxtimer::start

bool start(int milliseconds = -1, bool oneshot = false)

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

wxtimer_continuous start a normal, continuously running, timer
wxtimer_one_shot start a one shot timer

if the timer was already running, it will be stopped by this method before restarting it.


wxtimer::stop

void stop()

stops the timer.