MFC Countdown Timer

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

MFC Countdown Timer

 
0
  #1
Nov 8th, 2006
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

  1. m_iCount = 0;
  2. SetTimer(ID_TEST_TIMER, 1000, NULL);
  3. while(m_iCount <= 5)
  4. {
  5. }

However if I add the following it works fine.

  1. m_iCount = 0;
  2. SetTimer(ID_TEST_TIMER, 1000, NULL);
  3. while(m_iCount <= 5)
  4. {
  5. CString x;
  6. x.Format("%d",m_iCount);
  7. MessageBox(x);
  8. }

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?
Thanx,
Atrus
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: MFC Countdown Timer

 
0
  #2
Nov 8th, 2006
  1. while(m_iCount <= 5)
  2. {
  3. }
How many ways can you say infinite 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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Re: MFC Countdown Timer

 
0
  #3
Nov 8th, 2006
Why? Becasue I am a noob who forgot about Sleep();
Thanx for the help!!:o
Last edited by atrusmre; Nov 8th, 2006 at 3:51 pm.
Thanx,
Atrus
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 64
Reputation: atrusmre is an unknown quantity at this point 
Solved Threads: 0
atrusmre's Avatar
atrusmre atrusmre is offline Offline
Junior Poster in Training

Re: MFC Countdown Timer

 
0
  #4
Nov 13th, 2006
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?
  1. Sleep()
causes the program to pause, so what would I use?
Thanx,
Atrus
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: MFC Countdown Timer

 
0
  #5
Nov 13th, 2006
Why don't you read the documentation for Sleep() ????
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,413
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1470
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: MFC Countdown Timer

 
0
  #6
Nov 13th, 2006
Originally Posted by atrusmre View Post
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?
  1. 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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC