Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Timer program

This topic is 5370 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How would I go about making a program that has a 60 second timer? Basically I want the timer to be activated by just one keystroke and I would also like to add sounds to it ("10 seconds remaining" and such). Also, I would want this program to run while I''m in a different program, I mean I want to be able to turn the timer on while I''m in some other app. I know a bit of VB and C/C++. Any help would be appreciated or any tutorials you can point me in the direction of. Thanks.

Share this post

Link to post
Share on other sites
Why don''t you use the Window''s timer function? You can do all kinds of things with it as long as you don''t need high accuracy (like millisecond stuff). For a clock like your talking about it''s more than accurate.

//------- CREATE TIMER:
SetTimer(hwindow, NULL, 500, NULL ); // Start the timer for 500 ms

Then every 500 ms the timer sends a WM_TIMER message to the specified window callback function. After you are all done with it call

KillTimer(hwindow, NULL); // Kill off the timer

There are lots of variations on this theme (windows, callbacks, etc)!

If your looking for real accuracy and fast intervals for things like digital radio, music, etc., forget this approach!


Share this post

Link to post
Share on other sites
I would play about with clock() or GetTickCount(), I have made lots of useful timing functions just using clock() especially for animation but it''s probably easier to use the WM_TIMER message if you like working with windows stuff.

You would use the CLOCKS_PER_SEC constant to find 1 second then you would poll the clock function to get difference in the time for example, heres a quick demo...

#include <iostream>
#include <ctime>
using namespace std;

int main()
clock_t time_start = clock();
bool TimeElapse;

clock_t time_now = clock();
if((time_now - time_start) > CLOCKS_PER_SEC * 60)
TimeElapse = true;
TimeElapse = false;

time_start = clock();
cout << "DingDong!\n";

return 0;

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!