Timer program

Started by
4 comments, last by Anxac 20 years ago
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.
Advertisement
What platform? Windows?
VB has a timer component. I think I would start from there.



Stevie

Don''t follow me, I''m lost.
StevieDon't follow me, I'm lost.
Yes for Windows.
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!

Brian
Brian Reinhold
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();	while(true)	{		bool TimeElapse;		clock_t time_now = clock();		if((time_now - time_start) > CLOCKS_PER_SEC * 60)			TimeElapse = true;		else			TimeElapse = false;  		if(TimeElapse)		{			time_start = clock();			cout << "DingDong!\n";		}	}	return 0;}
-----------------------------Language: C++API: Win32, DirectXCompiler: VC++ 2003

This topic is closed to new replies.

Advertisement