How to Use Timer in MFC Dialog based Application?

Ali Ahmed picture Ali Ahmed · Aug 23, 2011 · Viewed 46k times · Source

I am developing MFC Dialog based application in Visual Studio 2008. I want to use timer that start on start of the application and continue to run and calls a function that performs my task? How can I do this?

Thanks

Answer

Ajay picture Ajay · Aug 23, 2011

Just use SetTimer method, and pass two arguments: Timer ID (any number), and the timeout in milliseconds. Then write up OnTimer implementation, and an entry ON_WM_TIMER inside BEGIN_MESSAGE_MAP...END_MESSAGE_MAP.

CWnd::SetTimer takes 3 parameters, but only 2 are required. Pass third argument as NULL.

CWnd::OnTimer