没有窗口怎么使用定时器

使用timeSetEvent


#include <stdio.h>
#include <Windows.h>
#include <Mmsystem.h>
#pragma comment(lib, "Winmm.lib")


void WINAPI OnTimeFunc(UINT wTimerID, UINT msg,DWORD dwUser,DWORD dwl,DWORD dw2)
{
	printf("OnTimeFunc\n");
} 

int main(int argc, char * argv[])
{
	MMRESULT timer_id;
	timer_id = timeSetEvent(1000, 1, (LPTIMECALLBACK)OnTimeFunc, DWORD(1), TIME_PERIODIC);

	if(NULL == timer_id)
	{
		printf("timeSetEvent error!--code:0x%x\n",GetLastError());
		return 0;
	}

	printf("input any key KillTimer!\n");
	getchar();
	timeKillEvent(timer_id); //释放定时器

	printf("input any key Exit!\n");
	return 1;
}


你可能感兴趣的:(定时器)