Lambda
Lambda

Reputation: 25

OnTimer never being called, unsure why?

Having some trouble here, right now I'm just trying to make an image move across the screen, the variables and positioning is working but for some reason the OnTimer is never called, I put a breakpoint inside it and it was never reached. No errors so I presume all methods and variables are defined correctly in the header.

Thanks in advance

BOOL Client::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    //StartGame();

    m_PlayerPosTop = 0;  // 384
    m_PlayerPosLeft = 0;
    m_PlayerImg.MoveWindow(m_PlayerPosLeft, m_PlayerPosTop, 16, 16);
    m_nTimer = SetTimer(0, 1000, 0);

    return TRUE;
}

    void Client::OnTimer(UINT_PTR nIDEvent)
{

    m_PlayerPosLeft++;
    m_PlayerImg.MoveWindow(m_PlayerPosLeft, m_PlayerPosTop, 16, 16);

    CDialogEx::OnTimer(nIDEvent);
}

Upvotes: 1

Views: 1174

Answers (1)

Dean Seo
Dean Seo

Reputation: 5703

As MFC is a message-driven system, one possible reason that you don't see your OnTimer fired is because you forgot to locate ON_WM_TIMER() in the right place.

BEGIN_MEESAGE_MAP(...)
     // ..
     ON_WM_TIMER()
     // ..
END_MESSAGE_MAP()

Upvotes: 2

Related Questions