I'm experimenting with a basic (template) MFC application, and I am looking to update the CDocument (representing the model) instance according to a timer event, for example, move a circle from one point in the client area to another point, according to elapsed time and velocity of the circle.
I've added the code to start the timer in the application class:
m_timer = m_pMainWnd->SetTimer( 16, 1000, NULL);
Which should send a timer message 60 times per second. However, I'm encountering several issues:
Adding a ON_WM_TIMER() entry to the message map for the derived CDocument .cpp file does not work, citing a c2446 error (casting a member function pointer to void pointer).
Trying the same with the concrete CView class does not cause an error, but the OnTimer function is never invoked.
The only place where OnTimer is ever invoked is in the derived CFrameWndEx class, using the following signature:
afx_msg void OnTimer( UINT_PTR nIDEvent );
As far as I can tell, there is no way for the CFrameWndEx to invoke changes in either the CView or CDocument derived classes.
I'm pretty sure this is simply down to my seriously lacking knowledge of MFC architecture, so I would appreciate some pointers.
CFrameWndExobject has no knowledge of either. - Ian YoungCMyDocument::OnTimer()function? - sergiolON_WM_TIMER(), and theOnTimer()function.ON_WM_TIMER()on aCDocumentwill never be handled, because it is defined to be treated byOnTimer, which is inCWnd. In the message loop there is some point on aCWndthat is callingOnTimer, a fact not happening onCDocumentderived classes. I suggest you to use Spy++ (Spy++ 64 on 64 bits build) to see the message workflow running. - sergiol