Advertisement

Get time in Visual C++

Started by October 10, 2002 01:57 PM
4 comments, last by dannyxyz23 22 years, 1 month ago
How do I make my program know that there has passed 1 millisecond. I mean, how do I calculate the actual time , a time in a few seconds and subtract them?
I'm not sure I understand your question correctly. You can use QueryPerformanceFrequency(), and QueryPerformanceCounter().


      float result;LARGE_INTEGER frequency, starttime, endtime;// Get the frequency of the high resolution counterQueryPerformanceFrequency(&frequency);// Get the start timeQueryPerformanceCounter(&starttime);// Do somethingQueryPerformanceCounter(&endtime);if((result = (float)((endtime.QuadPart - starttime.QuadPart) / frequency.QuadPart)) < 0.0001f){// Do something}else{// Do something else}    

Or you can use GetTickCount();


        DWORD starttime, endtime;starttime = GetTickCount();// Do somethingendtime = GetTickCount();if((float)(endtime - starttime) < 0.0001f){// do something}else{// do something else}      



I don't have a signature

[edited by - Brian Jones on October 10, 2002 3:37:01 PM]

[edited by - Brian Jones on October 10, 2002 3:37:43 PM]
I don't have a signature
Advertisement
You use the latter method if you hardware doesn''t have a high resolution timer.
I don't have a signature
Really thank you Brian. I used the GetTickCount and displayed an Opengl Pyramid. Then I looped back and checked if the time difference was smaller than 10 (hope it´s milliseconds,hhe). If it was, the Pyramid should move to the position when t = to + .01 (in seconds). But when I changed the time difference to 1 millisecond and gave it the position to t = to + 0.001 (seconds) it had a completely different velocity (it was slower). How can I solve it?
Ooops. Sorry. I made an error in my post. 0.0001 should be 1. I was going from ms to seconds.

[edited by - Brian Jones on October 10, 2002 4:22:36 PM]
I don't have a signature
Oh, thanks, but I noticed you meant it should be milliseconds
:-) . Got any idea of what''s going wrong?

This topic is closed to new replies.

Advertisement