943,884 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 9468
  • C RSS
Nov 8th, 2006
0

MFC Countdown Timer

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atrusmre is offline Offline
64 posts
since Mar 2005
Nov 8th, 2006
0

Re: MFC Countdown Timer

  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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,952 posts
since Aug 2005
Nov 8th, 2006
0

Re: MFC Countdown Timer

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atrusmre is offline Offline
64 posts
since Mar 2005
Nov 13th, 2006
0

Re: MFC Countdown Timer

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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atrusmre is offline Offline
64 posts
since Mar 2005
Nov 13th, 2006
0

Re: MFC Countdown Timer

Why don't you read the documentation for Sleep() ????
Moderator
Reputation Points: 572
Solved Threads: 115
Mentally Challenged Mod.
WolfPack is offline Offline
1,559 posts
since Jun 2005
Nov 13th, 2006
0

Re: MFC Countdown Timer

Click to Expand / Collapse  Quote originally posted by atrusmre ...
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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,952 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: DefWindowProc
Next Thread in C Forum Timeline: Calling C function from MATLAB





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC