dattebayo
dattebayo

Reputation: 2072

MFC OnTimer() method not working

I created an MFC dialog based app and wanted to add timer on the form. But it turns out that MFC is different than the .NET windows forms.

I added the ON_WM_TIMER() in the messagemap. and added the function definition for CMyDialog::OnTimer(UINT_PTR x) { }

But I am getting a compiler error in VS2005. I do not know what i am doing wrong. "error C2509: 'OnTimer' : member function not declared in 'CMyDialog'"

Help is greatly appreciated. Thanks.

Upvotes: 0

Views: 2184

Answers (2)

Serge Wautier
Serge Wautier

Reputation: 21888

Obviously, you forgot to declare the function in MyDialog.h, in CMyDialog declaration:

afx_msg void OnTimer(UINT_PTR x);

Note that afx_msg is purely informative and can be omitted.

Upvotes: 5

Mark Ransom
Mark Ransom

Reputation: 308432

The documentation for the ON_WM_TIMER map macro shows that you're doing the right thing. The only thing I can think of is that you have left the afx_msg qualifier off of your function definition.

Edit: At the risk of stating the obvious, did you also include the prototype of the OnTimer function in your class declaration?

Upvotes: 2

Related Questions