MFC OnTimer() method not working

喜你入骨 提交于 2019-12-25 03:24:57

问题


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.


回答1:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/7002590/mfc-ontimer-method-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!