Click here to Skip to main content
15,746,652 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I must use a timer that calls the function every 10 seconds, I searched on goole but I don't find a correct example..dou you have some examples?

I read solutions but my application use CDocument class, so WM_TIMER event isn't recognized and SetTimer idem..

What I have tried:

I searched on internet but there isn't a clear example
Updated 28-May-23 22:59pm

Call SetTimer, as you did, then you have to implement an OnTimer override in your window class that will handle the timer event. This is its prototype :
afx_msg void   OnTimer( UINT_PTR id );
You also have to add this line to your message map :
Remember that there can be several timers active at once so you should only service the event of interest in your handler - not all of them. That means your handler should look something like this :
void MyWindowClass::OnTimer( UINT_PTR timertId )
   if( timerId == MyTimerId )
      // handle timer event
   __super::OnTimer( eventId );  // let parent class have its shot at it
Share this answer
Member 14594285 29-May-23 4:36am    
yes but I have a CDocument class and ON_WM_TIMER isn't recognized
Rick York 29-May-23 12:06pm    
Please note that I wrote MyWindowClass. That means you have to implement this handler in a class with a window and a message loop. CDocument classes almost always have a CView-based class and the CView class has methods to access its associated CDocument object.
You need to use the SetTimer function (winuser.h) - Win32 apps | Microsoft Learn[^] and associated messages.
Share this answer
Member 14594285 26-May-23 10:47am    
I wrote:

m_nTimer = SetTimer(IDT_TIMER, 1000, NULL);

but I I have error in SetTimer
Richard MacCutchan 26-May-23 11:26am    
What error?
Member 14594285 26-May-23 11:37am    
I have an error inside the function SetTimer, elements are not recognized
Richard MacCutchan 26-May-23 12:27pm    
Then you need tob change them so that they are recognised.

Seriously, how do you expect us to help you if you do not provide any useful information? Please use the Improve question link above, and add complete details of the code you have and the exact error messages.
Member 14594285 29-May-23 5:03am    
I improved question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900