我的博客小站

不依赖窗口的定时器写法

#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;
}

 

posted on 2011-11-04 16:10  BIGSING  阅读(301)  评论(0编辑  收藏  举报

导航

我的博客小站