Timer dosen't work

This is a discussion on Timer dosen't work within the Windows Programming forums, part of the Platform Specific Boards category; Hi! This timer doesn't work. Coudle anyone please point out why? Code: //[MFC dialog based app] .... //we're online! so ...

  1. #1
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    365

    Timer dosen't work

    Hi!

    This timer doesn't work. Coudle anyone please point out why?

    Code:
    //[MFC dialog based app]
    ....
    //we're online! so setup the timer
    if(!m_bonline){//call only once after going online
        m_nTimer=SetTimer(1,1000,0);
        if(!m_nTimer)
          AfxMessageBox("SetTimer falied");
    }
    m_bonline=TRUE;
    ....
    ....
    void CDialuptimetickerDlg::OnTimer(UINT nIDEvent)
    {
      Beep(2000,1000);
      CDialog::OnTimer(nIDEvent);
    }
    ....
    SetTimer() is called, m_nTimer gets 1, but i can't hear the Beep() inside OnTimer.

    thx 4 any help.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,633
    I'm just going to assume you just pushed the button twice?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Where does it fail? (use break points to pause the code at a particular line, F9 in MSVC)

    Does the OnTimer handler get called?

    What does Beep() return?

    Have you tried using Beep() elsewhere?

    When you get the error what does GetLastError() return?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    365
    Does the OnTimer handler get called?
    Seems not. tried a brakepoint inside OnTimer(), but it never gets hit.

    Have you tried using Beep() elsewhere?
    yeah it works elsewhere.

    When you get the error what does GetLastError() return?
    returns no error 0, when called after SetTimer(). SetTimer returns a timer identifier (1), but OnTimer is not executed?
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Is your app very busy? WM_TIMER msgs are very low priority in the msg queue and can be ignored.

    It is the same dlg creating the timer as processing the timer msgs?



    Other than that looks good.

    Try....

    if(!m_bonline && !m_nTimer)


    and using a diff ID number

    ie
    #define ID_TIMER 40001

    m_nTimer=SetTimer(ID_TIMER,1000,NULL);

    //in OnTimer

    if(nIDEvent==m_nTimer)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    365
    did all that. but nothing!

    Is your app very busy? WM_TIMER msgs are very low priority in the msg queue and can be ignored.
    no.. i'm only doing a 1 ps loop to check if the user hangs up.

    It is the same dlg creating the timer as processing the timer msgs?
    yes. (CDialuptimetickerDlg)

    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  7. #7
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    365
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  8. #8
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,633
    I don't know MFC, but is it possible to get in CDialuptimetickerDlg's wnd proc? That way you could manualy check for WM_TIMER?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  9. #9
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    365
    gosh it's the while loop! i have to call the SetTimer from outside the evil while loop.

    edit: no wait.. it seems that i have to remove the loop altogether
    Last edited by geek@02; 09-14-2007 at 09:26 PM.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  2. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM
  3. Timer again.
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 05-04-2005, 10:19 PM
  4. sigh... why dosent this work?
    By jon_nc17 in forum C++ Programming
    Replies: 3
    Last Post: 05-20-2002, 08:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21