콘솔 어플리케이션으로 개발을 할때 타이머를 사용하기 위한 방법입니다.
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
using namespace std;
void CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)
{
cout << "Time : " << dwTime << endl;
cout.flush();
}
int _tmain(int argc, _TCHAR* argv[])
{
int Counter = 0;
MSG Msg;
UINT TimerID = SetTimer(NULL, 0, 500, &TimerProc);
cout << "TimerID : " << TimerID << endl;
if(!TimerID)
{
return 16;
}
while( GetMessage(&Msg, NULL, 0, 0) )
{
++Counter;
if(Msg.message == WM_TIMER)
cout << "Counter: " << Counter << "; timer message\n";
else
cout << "Counter: " << Counter << "; message: " << Msg.message << endl;
DispatchMessage(&Msg);
}
KillTimer(NULL, TimerID);
return 0;
}
댓글을 달아 주세요