View Full Version : How to create a timer

12-27-2001, 11:06 PM
I want to create a timer that will start when user press any key and will stop when it equal to 0 or when it reach the specific time.

Can I create the timer using sytem time (Windows time) and how do I read it in GLUT. Can anyone help me?

12-28-2001, 12:34 AM
This will return the windows time:
long time = timeGetTime();

You have to include "mmsystem.h"
and import the library "winmm.lib".

I wish it helps.
- nemesis -

[This message has been edited by nemesis (edited 12-28-2001).]

12-28-2001, 03:01 AM
Hey cyam95! If I understood your point, you want to create a timer like the Delphi TTimer component, don't you?

Well, you can create this using the SetTimer function. Example:

VOID CALLBACK Refresh(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime) {

KillTimer(hWnd, 41);

// put your code here


SetTimer(hWnd, 41, miliseconds, Refresh);

SeTimer function have four parameters! The first, you have to inform your Handle application, the second a ID number, that identifies your Timer (you can put what ever you want), the third is the time in miliseconds you want to wait, and the last is the Function the SetTimer function will call, when the time were elapsed.

Inside the Refresh function, you have to kill the timer, we used the KillTimer function. The first parameter is the hWnd (Handle) of your application, and the second, the code ID that you used to create the Timer (in our case 41). Note: If you don't to Kill the timer, you don't need! I only putted the KillTimer inside the 'Refresh' function because you said in your message, that you wanted to kill the Timer, when the time were elapsed!

I think it'll help you!!!!