Windows控制檯的定時器

thugfs發表於2014-10-10

程式每隔1秒定時輸出

i get a word:

Hello

原始碼如下:

#include <windows.h>
#include <stdio.h>
VOID CALLBACK TimerProc(HWND,UINT,UINT,DWORD)//回撥函式 
{ 
	printf("Hello\n");
}
int main()
{
	SetTimer(NULL,1,1000,TimerProc);//定時器
	MSG msg;
	while(GetMessage(&msg, NULL,NULL,NULL))//讀取訊息
	{
		if(msg.message == WM_TIMER)
		{
			printf("i get a word:\n");
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return 0;
}


相關文章