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 two 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
{\tt EVT
\_TIMER}
15 macro to connect it to the event handler which will receive
16 \helpref{wxTimerEvent
}{wxtimerevent
} notifications.
19 In any case, you must start the timer with
\helpref{Start
}{wxtimerstart
}
20 after constructing it before it actually starts sending notifications. It can
21 be stopped later with
\helpref{Stop
}{wxtimerstop
}.
23 \wxheading{Derived from
}
25 \helpref{wxObject
}{wxobject
}
27 \wxheading{Include files
}
33 \helpref{::wxStartTimer
}{wxstarttimer
},
\helpref{::wxGetElapsedTime
}{wxgetelapsedtime
},
\helpref{wxStopWatch
}{wxstopwatch
}
35 \latexignore{\rtfignore{\wxheading{Members
}}}
37 \membersection{wxTimer::wxTimer
}\label{wxtimerwxtimer
}
39 \func{}{wxTimer
}{\void}
41 Default constructor. If you use it to construct the object and don't call
42 \helpref{SetOwner
}{wxtimersetowner
} later, you must override
43 \helpref{Notify
}{wxtimernotify
} method to process the notifications.
45 \func{}{wxTimer
}{\param{wxEvtHandler *
}{owner
},
\param{int
}{id = -
1}}
47 Creates a timer and associates it with
{\it owner
}. Please see
48 \helpref{SetOwner
}{wxtimersetowner
} for the description of parameters.
50 \membersection{wxTimer::
\destruct{wxTimer
}}
52 \func{}{\destruct{wxTimer
}}{\void}
54 Destructor. Stops the timer if it is running.
56 \membersection{wxTimer::GetInterval
}{wxtimergetinterval
}
58 \constfunc{int
}{GetInterval
}{\void}
60 Returns the current interval for the timer (in milliseconds).
62 \membersection{wxTimer::IsOneShot
}\label{wxtimerisoneshot
}
64 \constfunc{bool
}{IsOneShot
}{\void}
66 Returns TRUE if the timer is one shot, i.e. if it will stop after firing the
67 first notification automatically.
69 \membersection{wxTimer::IsRunning
}\label{wxtimerisrunning
}
71 \constfunc{bool
}{IsRunning
}{\void}
73 Returns TRUE if the timer is running, FALSE if it is stopped.
75 \membersection{wxTimer::Notify
}\label{wxtimernotify
}
77 \func{void
}{Notify
}{\void}
79 This member should be overridden by the user if the default constructor was
80 used and
\helpref{SetOwner
}{wxtimersetowner
} wasn't called.
82 Perform whatever action which is to be taken periodically here.
84 \membersection{wxTimer::SetOwner
}\label{wxtimersetowner
}
86 \func{void
}{SetOwner
}{\param{wxEvtHandler *
}{owner
},
\param{int
}{id = -
1}}
88 Associates the timer with the given
{\it owner
} object. When the timer is
89 running, the owner will receive
\helpref{timer events
}{wxtimerevent
} with
90 id equal to
{\it id
} specified here.
92 \membersection{wxTimer::Start
}\label{wxtimerstart
}
94 \func{bool
}{Start
}{\param{int
}{ milliseconds = -
1},
\param{bool
}{ oneShot=FALSE
}}
96 (Re)starts the timer. If
{\it milliseconds
} parameter is -
1 (value by default),
97 the previous value is used. Returns FALSE if the timer could not be started,
98 TRUE otherwise (in MS Windows timers are a limited resource).
100 If
{\it oneShot
} is FALSE (the default), the
\helpref{Notify
}{wxtimernotify
}
101 function will be called repeatedly until the timer is stopped. If TRUE,
102 it will be called only once and the timer will stop automatically.
104 \membersection{wxTimer::Stop
}\label{wxtimerstop
}
106 \func{void
}{Stop
}{\void}
110 \section{\class{wxTimerEvent
}}\label{wxtimerevent
}
112 wxTimerEvent object is passed to the event handler of timer events.
117 class MyFrame : public wxFrame
121 void OnTimer(wxTimerEvent& event);
127 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
128 EVT_TIMER(TIMER_ID, MyFrame::OnTimer)
132 : m_timer(this, TIMER_ID)
134 m_timer.Start(
1000); //
1 second interval
137 void MyFrame::OnTimer(wxTimerEvent& event)
139 // do whatever you want to do every second here
144 \wxheading{Include files
}
150 \helpref{wxTimer
}{wxtimer
}
152 \latexignore{\rtfignore{\wxheading{Members
}}}
154 \membersection{wxTimerEvent::GetInterval
}\label{wxtimereventgetinterval
}
156 \constfunc{int
}{GetInterval
}{\void}
158 Returns the interval of the timer which generated this event.