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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.