DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   MFC Countdown Timer (http://www.daniweb.com/forums/thread60908.html)

atrusmre Nov 8th, 2006 4:15 am
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?

Ancient Dragon Nov 8th, 2006 9:04 am
Re: MFC Countdown Timer
 
while(m_iCount <= 5)
        {
        }
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.

atrusmre Nov 8th, 2006 3:49 pm
Re: MFC Countdown Timer
 
Why? Becasue I am a noob who forgot about Sleep();
Thanx for the help!!:o

atrusmre Nov 13th, 2006 4:55 am
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?
Sleep()
causes the program to pause, so what would I use?

WolfPack Nov 13th, 2006 6:16 am
Re: MFC Countdown Timer
 
Why don't you read the documentation for Sleep() ????

Ancient Dragon Nov 13th, 2006 7:15 am
Re: MFC Countdown Timer
 
Quote:

Originally Posted by atrusmre (Post 275571)
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.


All times are GMT -4. The time now is 12:39 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC