Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3711
Number of posts: 9173

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
How can I use a timer in Win32?? Posted by Sephiroth on 3 Nov 2000 at 5:52 PM
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!<br>
<br>
-Seph


Edit Report
Re: How can I use a timer in Win32?? Posted by KMS on 6 Nov 2000 at 2:25 PM
Hey Seph,<br>
<br>
Try this code<br>
<br>
// wait for 500 ms<br>
DWORD dwTime = GetTickCount();<br>
while( ( GetTickCount() - dwTime ) > 500 );<br>
<br>
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!<br>
<br>
: 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!<br>
: <br>
: -Seph<br>
: <br>
<br>
<br>
<br>



Edit Report
Re: Re: How can I use a timer in Win32?? Posted by KMS on 6 Nov 2000 at 2:26 PM
Should be<br>
while( ( GetTickCount() - dwTime ) < 500 );<br>
<br>
: Hey Seph,<br>
: <br>
: Try this code<br>
: <br>
: // wait for 500 ms<br>
: DWORD dwTime = GetTickCount();<br>
: while( ( GetTickCount() - dwTime ) > 500 );<br>
: <br>
: 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!<br>
: <br>
: : 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!<br>
: : <br>
: : -Seph<br>
: : <br>
: <br>
: <br>
: <br>
: <br>
: <br>
<br>



Edit Report
Re: Re: Re: How can I use a timer in Win32?? Posted by Sephiroth on 7 Nov 2000 at 10:58 AM
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.<br>
<br>
for(int x = 0; x < 256; x++)<br>
{<br>
while((GetTickCount() - dwTime) < 500)<br>
FillRect(fDC, &faderect, (CreateSolidBrush(RGB(255, x, x))));<br>
}<br>
<br>
Any other ideas? Oh and just in case it matters, all of this code is in "fight.dll", not my executeable.<br>
<br>
-Seph


Edit Report
Re: Re: Re: Re: How can I use a timer in Win32?? Posted by KMS on 7 Nov 2000 at 12:43 PM
So? why its not good? You can write a function like this:<br>
<br>
void MyDelay( DWORD dwMilliSeconds )<br>
{<br>
DWORD dwInitial = GetTickCount();<br>
while( ( GetTickCount() - dwInitial ) < dwMilliSeconds );<br>
}<br>
<br>
As I understand, you want a delay, thats a difference between two snapshots of time. GetTickCount can do that perfectly well.<br>
<br>
Or am I missing something, again!<br>
<br>
: 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.<br>
: <br>
: for(int x = 0; x < 256; x++)<br>
: {<br>
: while((GetTickCount() - dwTime) < 500)<br>
: FillRect(fDC, &faderect, (CreateSolidBrush(RGB(255, x, x))));<br>
: }<br>
: <br>
: Any other ideas? Oh and just in case it matters, all of this code is in "fight.dll", not my executeable.<br>
: <br>
: -Seph<br>
: <br>
<br>



Edit Report
Re: Re: Re: Re: Re: How can I use a timer in Win32?? Posted by Sephiroth on 8 Nov 2000 at 9:15 AM
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!<br>
<br>
-Seph





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.