Realtime Timer

This is a discussion on Realtime Timer within the C++ Programming forums, part of the General Programming Boards category; HI! I would like to know how to put a realtime timer in my program, like a stopwatch. I tried ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    50

    Realtime Timer

    HI!
    I would like to know how to put a realtime timer in my program, like a stopwatch. I tried using the Time_t function but it can only display time when an event occurs. Maybe someone can tell me how to make a timer wich does not need a 'direct' event.(just like the computer clock)
    I dont know half as many of you half as well as I should like, and I like less than half of you half as well as you deserve...

  2. #2
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    you could use the GetTickCount() function. It returns the number of milliseconds since your program started.

    make a variable to hold a starting point, and then where you want to stop would be stored in a second variable. subtract the second from the first to get the total time in milliseconds.

    int a = GetTickCount();

    // the thing you want to time

    int b = GetTickCount();

    int totalTime = b - a;
    I came up with a cool phrase to put down here, but i forgot it...

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    50
    I know what you mean, and that's exactly what I did before. What I really mean is a timer that displays time during the program, even when no event occurs. Imagine a program that does cout<<"hi"; each second.(just as an example ofcourse)
    I dont know half as many of you half as well as I should like, and I like less than half of you half as well as you deserve...

  4. #4
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    search msdn for SetTimer function, it's what you are looking for, this function will send WM_TIMER message every x ms (you specify)
    hth

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 01:23 AM
  2. How to build a timer that counts the seconds elapsed?
    By Nazgulled in forum C Programming
    Replies: 17
    Last Post: 05-28-2007, 01:26 PM
  3. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 07:25 PM
  4. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 05:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21