The V C++ GUI Framework:vTimer

From EDM2
Jump to: navigation, search

A class for getting timer events.


[vquickr.htm#vTimer <v/vtimer.h>]
Class name:


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


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.