Thread: Realtime Timer

  1. #1
    Registered User
    Join Date
    Apr 2003

    Realtime Timer

    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)

  2. #2
    Registered User
    Join Date
    Feb 2002
    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
    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)

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

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, 12: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, 12:26 PM
  3. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  4. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM