Thread: Timer dosen't work

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    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.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    I'm just going to assume you just pushed the button twice?

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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 geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    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?
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    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 geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    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)

    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  7. #7
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  8. #8
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    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?

  9. #9
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    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.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur 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