Confused about CWnd::SetTimer

I'm trying to start a timer in a CView class. I used the "Add windows message handler" class wizard to create the function:

void CTestclientView::OnTimer(UINT nIDEvent)
      // TODO: Add your...

What is the correct call to start the timer? I'm trying to start the timer using:

m_n_Timer = SetTimer(1, 100, CTest1View::OnTimer);

But I get a compiler error:

cannot convert parameter 3 from 'void (unsigned int)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'

I'm confused. the actual prototype for CWnd::SetTimer is

UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );

But the class wizard created a function with only one parameter.

Should my OnTimer function have a prototype like above.


All I want is a 1/10th of a second timer to do some screen updates.

Thanks for the help.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

chensuConnect With a Mentor Commented:
Use the following code instead.

m_n_Timer = SetTimer(1, 100, NULL);

If you specify NULL, Windows sends the WM_TIMER message. You have already added the WM_TIMER message handler (OnTimer). Otherwise, the 3rd parameter specifies the address of the callback function, in which case Windows calls the callback function instead of sending the message.
RickG_99Author Commented:
Ok... I started off doing that but I was getting an ASSERT when I called SetTimer. Here's the ASSERT:

_AFXWIN_INLINE UINT CWnd::SetTimer(UINT nIDEvent, UINT nElapse,      void (CALLBACK* lpfnTimer)(HWND, UINT, UINT, DWORD)) { ASSERT(::IsWindow(m_hWnd)); return ::SetTimer(m_hWnd, nIDEvent, nElapse,(TIMERPROC)lpfnTimer); }

This is why I thouht I had the wrong parameters for my OnTimer function.

I'm calling SetTimer in the constructor for the CView class, is this a problem?

Am I asserting because the window isn't finished being constructed?

Again... THANKS A LOT for your help!

There is no window created yet in the constructor. Call SetTimer in the OnCreate and KillTimer in the OnDestroy.
RickG_99Author Commented:
Ahh... All is good now!!

Thanks so much for your help!
All Courses

From novice to tech pro — start learning today.