MFC text box timer

Discussion in 'MFC' started by lightbulb, Apr 28, 2009.

  1. lightbulb

    lightbulb New Member

    Joined:
    Apr 28, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    im a having a hard time seting up clock for MFC text box... I would like my text box dispay timer from 10:00 up to 00:00 .. hope someone can help I really do need it thx alot in advance....:happy:
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    What is the problem you are facing.

    Have variables that updates based on the timer tick
     
  3. lightbulb

    lightbulb New Member

    Joined:
    Apr 28, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    This is what i would like to happen.. i got 1 textbox and 1 command box.. once 1 click my command box i would like for my textbox to start counting down from 10 minutes up to 0 minutes.. i tried using Sleep(1000) function but it doesnt work ..
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    No thats not the way.

    Have 2 variables for Minutes and Seconds and start counting them down each time that function is called.

    Use the WM_TIMER event to be used for that function
     
  5. lightbulb

    lightbulb New Member

    Joined:
    Apr 28, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    well thanks. im just recently started learning MFC and sad thing about that is no is teaching me.. i'll just try to learn what WM_TIMER event does..... thx again... ^^
     
  6. lightbulb

    lightbulb New Member

    Joined:
    Apr 28, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hope this not too much.. can you write me s simple program using Settimer... i cant understand anything writen on the web about settimers and making a countdown timer... if its ok.. really do appreciate it ^^,,,,:)
     
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Add ON_WM_TIMER() in BEGIN_MESSAGE_MAP

    And then the following Function

    void CTestDlg::OnTimer(UINT_PTR nIDEvent)

    Also there should be a variable called m_seconds

    And then in that function increase for every seconds tick
     
  8. lightbulb

    lightbulb New Member

    Joined:
    Apr 28, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    i dont know if this is right...
    void CtimerDlg::OnBnClickedButton1()
    {

    UINT sec;
    char u[90];
    CString y;
    sec=SetTimer(60,1000,0);
    sprintf(u,"%d",sec);
    y=u;
    a.SetWindowText(y);


    }
    is the value of sec will decrease from 60-0 every second upon clicking my command button? but how can i update the value of my text box every second?
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You need to have the variables in the class and not local to the function
     
  10. lightbulb

    lightbulb New Member

    Joined:
    Apr 28, 2009
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    • thx a lot shabbir.. but i think i need to study MFC w/ pictures cause i can see what youre saying.. sry for being so noobish... thx alot for you help...
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I agree but what I meant in the last post was related to C++ and not MFC
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice