没有窗口怎么使用定时器

Posted zhuhuibeishadiao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了没有窗口怎么使用定时器相关的知识,希望对你有一定的参考价值。

使用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;



以上是关于没有窗口怎么使用定时器的主要内容,如果未能解决你的问题,请参考以下文章