不依赖窗口的定时器写法
#include <Windows.h>
#include <Mmsystem.h>
#pragma comment(lib, "Winmm.lib")
void WINAPI OnTimeFunc(UINT wTimerID, UINT msg,DWORD dwUser,DWORD dwl,DWORD dw2);
int main(int argc, char * argv[])
{
MMRESULT timer_id;
timer_id = timeSetEvent(5000, 1, (LPTIMECALLBACK)OnTimeFunc, DWORD(1), TIME_PERIODIC);
if(NULL == timer_id)
{
OutputDebugString("timeSetEvent() failed with error");
return 0;
}
while(true)
{
Sleep(2000);
}
timeKillEvent(timer_id); //释放定时器
return 1;
}
void WINAPI OnTimeFunc(UINT wTimerID, UINT msg,DWORD dwUser,DWORD dwl,DWORD dw2)
{
OutputDebugString("OnTimeFunc");
return;
}