首页 > 其他 > 详细

SetTimer 问题

时间:2015-01-30 09:17:15      阅读:293      评论:0      收藏:0      [点我收藏+]



在控制台下,以如下方式定义一个定时器:

UINT_PTR TimerID = SetTimer(NULL,1,1000,MyTimerProc);

其回调函数如下定义:
VOID CALLBACK TimerProc(
  HWND hwnd,         // handle to window 
  UINT uMsg,         // WM_TIMER message  
  UINT_PTR idEvent,  // timer identifier  
  DWORD dwTime       // current system time
  );
按以上定义方式,程序会报以下错误:
error C2664: ‘SetTimer‘ : cannot convert parameter 4 from ‘void (struct HWND__ *,unsigned int,unsigned long,unsigned long)‘ to ‘void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)‘       None of the functions with this name in scope match the target type
错误类型为:回调函数类型不一致。
解决方法为:将MyTimerProc回调函数进行强转。
UINT_PTR TimerID = SetTimer(NULL,1,1000,(TIMERPROC)MyTimerProc);

注:以上错误只在vs6.0中出现,在更高版本的vs中无需对回调函数进行强转。

本文出自 “whatever957” 博客,请务必保留此出处http://whatever957.blog.51cto.com/6835003/1609843

SetTimer 问题

原文:http://whatever957.blog.51cto.com/6835003/1609843

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!