• Announcements

Archived

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

Timer program

Recommended Posts

Anxac    122
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 on other sites
Rayno    511
What platform? Windows?

Share on other sites
stevie56    145
VB has a timer component. I think I would start from there.

Stevie

Anxac    122
Yes for Windows.

Share on other sites
Gyannea    122
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

#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;}