方法一:
SetTimer(NULL, 0, 1000, (TIMERPROC)Timer2Proc);
VOID CALLBACK Timer2Proc(
HWND hWnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
)
{
return;
}
方法二:
// DLL中的线程函数可以象这样使用Timer
UINT ThreadProc(LPVOID)
{
SetTimer(NULL, 1, 5000, NULL);
MSG msg;
// PeekMessage 强制系统为该线程建立消息栈
PeekMessage(&msg, NULL, NULL, NULL, FALSE);
while (GetMessage(&msg, NULL, NULL, NULL))
{
switch (msg.message)
{
case WM_TIMER:
{
// 这里每5秒钟执行一次
}
break;
}
//TranslateMessage(&msg);
//DispatchMessage(&msg);
}
KillTimer(NULL, 1);
return 0;
}
方法三:
创建一个线程, 反复读系统时间不就可以了? 如果定时要求不严,用Sleep就可以了
UINT TimerThread(LPVOID pama)
{
UINT oldTickCount, newTickCount;
oldTickCount = GetTickCount();
while(TRUE)
{
while(TRUE)
{
newTickCount = GetTickCount();
if(newTickCount - oldTickCount >= 100)
{
oldTickCount = newTickCount;
break;
}
}
TimeProc();
}
return 0;
}
大约每100ms 调用一次TimeProc();