A timer that does not stop program

Started by
1 comment, last by Syndicate 20 years ago
I am building a program in c++ that takes Morse code input from a mouse (left click short -- right click long ) and translates it into text -> output to screen . I want to make a timer that is off to the side of the Windows Form and counts down from 10 to 0. Each time a button is clicked the timer is reset. When Zero is reached (b/c no buttons pressed in x amount of time) I would like the timer to make a function call or pass a value to the Decode() function that takes all inputs from the mouse ( shorts and longs ex : dataArray[.--.-]) and translate them. I have the Decode() working and when a string ''trans'' is passed it takes everything out of dataArray and prints that letter to the screen. The problem is the timer. I can''t get the timer to count down and let the program still take inputs from the mouse. Also when I try to set the text of the timeBoxlable to the int if the timer and it give me "can not convert type int to System string __gc* " error .. // int x; for (x=10; x>0; x--) { textBoxlable->Text = x; } // Thank you, Syndicate
Advertisement
If you are using MFC (which it looks like your not but i''m gonna tell you anyway ) then you can use the SetTimer function... This function allows you to callback a function after a specified period of time, once the time is up a WM_TIMER message is sent to your window.

There may be something similar in the .NET windows programming, but i don''t know much about that.

As for your error of not being able to convert from an int to string... you''ll need to do this:

for (x=10; x>0; x--) {textBoxlable->Text = Convert::ToString(x);} 
You could try multithreading:

#include <process.h> int counter = 10; int isProgramFinished = 0; void CountDown(void *pParam); void main(void){	threadID = _beginthread(CountDown, 0, NULL); 	DoMainLoopUntilExit(); 	isProgramFinished = 1;} void CountDown(void *pParam){	while(!isProgramFinished)	{		for( ; counter >= 0; counter--)			Sleep(100); // Wait 100 milliseconds & don''t waste CPU time 		ConvertCode(); 		counter = 10;	}}

This topic is closed to new replies.

Advertisement