沒有窗口的定時器



在沒有窗口的程序中,使用定時器:

#include <windows.h>
#include <iostream>
using namespace std;

DWORD dwTimeId = 0;
VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
	if(dwTimeId == idEvent)
	{
		static DWORD i = 0;
		cout<<"Timer Proc : "<<++i<<endl;

		if(i == 10)
		{
			KillTimer(NULL, dwTimeId);
			cout<<"Timer End!!"<<endl;
			PostQuitMessage(0);
		}
	}
}

int main()
{
	dwTimeId = SetTimer(NULL, 1, 500, TimerProc);
	MSG msg;
	while(GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	cout<<"Process End!!"<<endl;
	return 0;
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章