VTimer: Difference between revisions
Created page with "A class for getting timer events. ==Synopsis== ; '''Header:''' : <tt>[vquickr.htm#vTimer <v/vtimer.h>]</tt> ; '''Class name:''' : vTimer ; '''Hierarchy:''' : vTimer ==Descript..." |
mNo edit summary |
||
Line 2: | Line 2: | ||
==Synopsis== | ==Synopsis== | ||
; '''Header:''' | ; '''Header:''' | ||
: <tt>[vquickr.htm#vTimer <v/vtimer.h>]</tt> | : <tt>[vquickr.htm#vTimer <v/vtimer.h>]</tt> | ||
Line 11: | Line 10: | ||
==Description== | ==Description== | ||
This is a utility class that allows you to get events driven by the system timer. The accuracy and resolution of timers on various systems varies, so this should be used only to get events on a more or less regular basis. Use the C library <tt>time</tt> routines to get real clock time. | This is a utility class that allows you to get events driven by the system timer. The accuracy and resolution of timers on various systems varies, so this should be used only to get events on a more or less regular basis. Use the C library <tt>time</tt> routines to get real clock time. | ||
Line 17: | Line 15: | ||
==New Methods== | ==New Methods== | ||
====vTimer==== | ====vTimer==== | ||
This constructs a timer object. The timer doesn't run until you start it with <tt>TimerSet</tt>. To make a timer useful, you can override the constructor to add a pointer to a window, and then use that pointer from within your <tt>TimerTick</tt> method to do something in that window: <tt>myTimer(vWindow* useWindow)</tt>. | This constructs a timer object. The timer doesn't run until you start it with <tt>TimerSet</tt>. To make a timer useful, you can override the constructor to add a pointer to a window, and then use that pointer from within your <tt>TimerTick</tt> method to do something in that window: <tt>myTimer(vWindow* useWindow)</tt>. | ||
====int TimerSet(long interval)==== | ====int TimerSet(long interval)==== | ||
This starts the timer going. The timer will call your overridden <tt>TimerTick</tt> method approximately every <tt>interval</tt> milliseconds until you stop the timer. Most systems don't support an unlimited number of timers, and <tt>TimerSet</tt> will return 0 if it couldn't get a system timer. | This starts the timer going. The timer will call your overridden <tt>TimerTick</tt> method approximately every <tt>interval</tt> milliseconds until you stop the timer. Most systems don't support an unlimited number of timers, and <tt>TimerSet</tt> will return 0 if it couldn't get a system timer. | ||
====void TimerStop()==== | ====void TimerStop()==== | ||
Calling this stops the timer, but does not destruct it. | Calling this stops the timer, but does not destruct it. | ||
====void TimerTick()==== | ====void TimerTick()==== | ||
This method is called by the system every interval milliseconds (more or less). The way to use the timer is to derive your own class, and override the <tt>TimerTick</tt> method. Your method will be called according to the interval set for the timer. Note that you can't count on the accuracy of the timer interval. | This method is called by the system every interval milliseconds (more or less). The way to use the timer is to derive your own class, and override the <tt>TimerTick</tt> method. Your method will be called according to the interval set for the timer. Note that you can't count on the accuracy of the timer interval. | ||
[[Category: | [[Category:V C++ GUI Framework]] |
Revision as of 17:41, 1 March 2017
A class for getting timer events.
Synopsis
- Header:
- [vquickr.htm#vTimer <v/vtimer.h>]
- Class name:
- vTimer
- Hierarchy:
- vTimer
Description
This is a utility class that allows you to get events driven by the system timer. The accuracy and resolution of timers on various systems varies, so this should be used only to get events on a more or less regular basis. Use the C library time routines to get real clock time.
The V Appgen utility offers an option for adding a timer to the status bar. Looking at that generated code is a good way to understand vTimer objects.
New Methods
vTimer
This constructs a timer object. The timer doesn't run until you start it with TimerSet. To make a timer useful, you can override the constructor to add a pointer to a window, and then use that pointer from within your TimerTick method to do something in that window: myTimer(vWindow* useWindow).
int TimerSet(long interval)
This starts the timer going. The timer will call your overridden TimerTick method approximately every interval milliseconds until you stop the timer. Most systems don't support an unlimited number of timers, and TimerSet will return 0 if it couldn't get a system timer.
void TimerStop()
Calling this stops the timer, but does not destruct it.
void TimerTick()
This method is called by the system every interval milliseconds (more or less). The way to use the timer is to derive your own class, and override the TimerTick method. Your method will be called according to the interval set for the timer. Note that you can't count on the accuracy of the timer interval.