MFC Countdown Timer
I am writing a MFC application and need to have the program pause for a few seconds. I am trying to use the OnTimer event and am having troubles. The following code causes the program to freeze and stop responding
m_iCount = 0;
SetTimer(ID_TEST_TIMER, 1000, NULL);
while(m_iCount <= 5)
{
}
However if I add the following it works fine.
m_iCount = 0;
SetTimer(ID_TEST_TIMER, 1000, NULL);
while(m_iCount <= 5)
{
CString x;
x.Format("%d",m_iCount);
MessageBox(x);
}
In both of these examples the program is suppose to wait 5 seconds before continuing. Also note that m_iCount is suppose to incrament everytime the ID_TEST_TIMER event is called. Any suggestions on what I am doing wrong and can do to fix it?
atrusmre
Junior Poster in Training
64 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
while(m_iCount <= 5)
{
}
How many ways can you sayinfinite loop ? and it is consuming nearly all CPU time?
why are you making it so difficult ? If you goal is for the program to pause for 5 second, just call Sleep() function. No need for that timer.
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
Why? Becasue I am a noob who forgot about Sleep();
Thanx for the help!!:o
atrusmre
Junior Poster in Training
64 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
Ok, so here's a spin off of the previous. If I wanted the user to only have say 20 seconds to enter text in an edit box before it grayed out, how would I go about that?
Sleep()
causes the program to pause, so what would I use?
atrusmre
Junior Poster in Training
64 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
Why don't you read the documentation for Sleep() ????
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Ok, so here's a spin off of the previous. If I wanted the user to only have say 20 seconds to enter text in an edit box before it grayed out, how would I go about that?
Sleep()
causes the program to pause, so what would I use?
You can't use Sleep() in that situation because Sleep will not allow the user to do anything during that time. I have not tried it but I think you can use sometime like this example which is implements a timeout for MessageBox. In a nutshell, you set a timer to kick off in 20 seconds. In the timer event check of the user has typed anything in the edit control and if not then send the control a WM_CLOSE message.
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341