SetTimer的抓狂问题

来源:百度知道 编辑:UC知道 时间:2024/09/21 09:00:19
首先写一个如下格式的回调函数
void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime);
然后再用SetTimer(1,100,TimerProc)函数来建一个定时器
编译的错误:
error C2664: 'SetTimer' : cannot convert parameter 3 from 'void (struct HWND__ *,unsigned int,unsigned long,unsigned long)' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned in
t,unsigned long)'
None of the functions with this name in scope match the target type
到底做何解释?错误在哪里?
请问三楼的朋友,为什么msdn上没有注名需要强制转换,你是怎么知道的?

TimerProc的定义:

VOID CALLBACK TimerProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_TIMER message
UINT_PTR idEvent, // timer identifier
DWORD dwTime // current system time
);

还有,调用的时候:
SetTimer(hwnd, // handle to main window
IDT_TIMER3, // timer identifier
5000, // 5-second interval
(TIMERPROC) MyTimerProc); // timer callback

需要显示的转换一下。

SetTimer(1,100,&TimerProc)

不用你特意指定他的回调函数,给NULL就行了,调用的时候用标号来判断是哪个定时器就行了.