Click here to Skip to main content
15,891,633 members
Articles / Programming Languages / C++

Low resolution timer class for Visual C++ and GNU C++ under MingW

Rate me:
Please Sign up or sign in to vote.
3.94/5 (9 votes)
9 Jan 20062 min read 74.3K   2K   21  
LRTimer - universal low resolution timer class with its own thread.
#include <stdlib.h>
#include "lrtimer.h"

using namespace std;

// define callback function
VOID callback(int i) {
  static DWORD cnt = 0;
  char c;
  cnt++;
  switch (cnt % 4) {
    case 0: c = '|'; break;
    case 1: c = '/'; break;
    case 2: c = '-'; break;
    case 3: c = '\\';
  }
  printf("\b\b\b\b\b\b\b%c %d",c,i);
}


int main(int argc, char *argv[])
{

  LRTimer lrt;
  lrt.setCallbackFunction(&callback);
  lrt.setInterval(50);
  lrt.start();
  getchar();
  lrt.stop();
  getchar();
  lrt.start(200);
  getchar();
  lrt.stop();
  system("PAUSE");
  return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Systems Engineer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions