Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How can I use a timer in Win32??

I'm trying to figure out how to use timers in Win32 so that I can time certain events, such as fade-ins. I currently use a for(x,x,x) loop, but even though that works great on our old p1/200mmx, it is un-noticeable on the p3/500. I would like to time it to about 500ms intervals for the next shading. Any help would be greatly appreciated. Thanks for your time!



-Seph


Comments

  • Hey Seph,



    Try this code



    // wait for 500 ms

    DWORD dwTime = GetTickCount();

    while( ( GetTickCount() - dwTime ) > 500 );



    If you want a very accurate timer, check out the multimedia timer functions in MSDN, I think I posted something about that in here a while ago, or maybe the C++ board. Cant remember!



    : I'm trying to figure out how to use timers in Win32 so that I can time certain events, such as fade-ins. I currently use a for(x,x,x) loop, but even though that works great on our old p1/200mmx, it is un-noticeable on the p3/500. I would like to time it to about 500ms intervals for the next shading. Any help would be greatly appreciated. Thanks for your time!

    :

    : -Seph

    :










  • Should be

    while( ( GetTickCount() - dwTime ) < 500 );



    : Hey Seph,

    :

    : Try this code

    :

    : // wait for 500 ms

    : DWORD dwTime = GetTickCount();

    : while( ( GetTickCount() - dwTime ) > 500 );

    :

    : If you want a very accurate timer, check out the multimedia timer functions in MSDN, I think I posted something about that in here a while ago, or maybe the C++ board. Cant remember!

    :

    : : I'm trying to figure out how to use timers in Win32 so that I can time certain events, such as fade-ins. I currently use a for(x,x,x) loop, but even though that works great on our old p1/200mmx, it is un-noticeable on the p3/500. I would like to time it to about 500ms intervals for the next shading. Any help would be greatly appreciated. Thanks for your time!

    : :

    : : -Seph

    : :

    :

    :

    :

    :

    :






  • That's no good. My Borland help file says that "GetTickCount" just returns the number of milliseconds since Windoze was started. Also says that at 49.7 days it will wrap to 0. Here is the fade from red (after the screen fills with blood) to black code.



    for(int x = 0; x < 256; x++)

    {

    while((GetTickCount() - dwTime) < 500)

    FillRect(fDC, &faderect, (CreateSolidBrush(RGB(255, x, x))));

    }



    Any other ideas? Oh and just in case it matters, all of this code is in "fight.dll", not my executeable.



    -Seph


  • So? why its not good? You can write a function like this:



    void MyDelay( DWORD dwMilliSeconds )

    {

    DWORD dwInitial = GetTickCount();

    while( ( GetTickCount() - dwInitial ) < dwMilliSeconds );

    }



    As I understand, you want a delay, thats a difference between two snapshots of time. GetTickCount can do that perfectly well.



    Or am I missing something, again!



    : That's no good. My Borland help file says that "GetTickCount" just returns the number of milliseconds since Windoze was started. Also says that at 49.7 days it will wrap to 0. Here is the fade from red (after the screen fills with blood) to black code.

    :

    : for(int x = 0; x < 256; x++)

    : {

    : while((GetTickCount() - dwTime) < 500)

    : FillRect(fDC, &faderect, (CreateSolidBrush(RGB(255, x, x))));

    : }

    :

    : Any other ideas? Oh and just in case it matters, all of this code is in "fight.dll", not my executeable.

    :

    : -Seph

    :






  • That will work perfectly. I didn't think of storing the current Tick and using it later. I'll try this and see what happens. It's heck just seeing a quick flash of red and black before the battle scene, lol!



    -Seph


Sign In or Register to comment.