Link to home
Start Free TrialLog in
Avatar of RickG_99
RickG_99

asked on

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...
      
      CView::OnTimer(nIDEvent);
}

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.

void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD)

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

Thanks for the help.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RickG_99
RickG_99

ASKER

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!

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

Thanks so much for your help!