Created
July 19, 2012 10:15
-
-
Save hirosof/3142871 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <Windows.h> | |
| #pragma comment(lib,"winmm.lib") | |
| VOID CALLBACK TimeP(HWND hwnd , UINT msg , UINT_PTR idEv , DWORD dwTime); | |
| unsigned int ms = 0 ; | |
| int main(void){ | |
| unsigned int setms , timerperiod , ret=0; | |
| printf("タイマーにセットする秒数をミリ秒単位で入力してください\n -> "); | |
| scanf_s("%u",&setms); | |
| printf("タイマー精度を設定する場合はミリ秒単位で入力してください。1ms以上の入力で設定します。\n -> "); | |
| scanf_s("%u",&timerperiod); | |
| if(timerperiod)timeBeginPeriod(timerperiod); | |
| printf("\n精度:%u タイマー:%u\n",timerperiod,setms); | |
| ms = timeGetTime(); | |
| ret = SetTimer(NULL,0,setms,(TIMERPROC)TimeP); | |
| while(!(GetKeyState(VK_ESCAPE) & 0x8000)); | |
| KillTimer(NULL,ret); | |
| if(timerperiod)timeEndPeriod(timerperiod); | |
| } | |
| VOID CALLBACK TimeP(HWND hwnd , UINT msg , UINT_PTR idEv , DWORD dwTime){ | |
| printf("\rTimer = %u ms (PCTIME = %d ms)", dwTime - ms , dwTime); | |
| ms = dwTime; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment