Test Code/C++
WinAPI - GetTickCount 함수로 sleep 함수 만들기
yaks101
2013. 12. 21. 00:25
- 파일명 : GetTickCount_Test.cpp
- 컴파일 : g++ -Wall -o GetTickCount_Test.exe GetTickCount_Test.cpp
windows.h 에는 Sleep 라는 함수가 있습니다.
#include <windows.h>
#include <iostream>
using namespace std;
void sleep(int iMilliseconds)
{
int iStart = GetTickCount();
while ((int)(GetTickCount() - iStart) < iMilliseconds){}
}
int main()
{
int iStart;
int iEnd;
iStart = GetTickCount();
sleep(1000);
iEnd = GetTickCount();
cout << iEnd - iStart << endl;
return 0;
}