セットタイマーイベント timeSetEvent()winmm.libのtimeSetEvent()APIで、周期的にコールバック関数を呼び出すことができます。 #include "stdafx.h" #include <windows.h> #include <mmsystem.h> #pragma comment(lib, "winmm.lib") void CALLBACK timer_handle(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) { static int iCount = 0; printf("timer tick = %d\r\n", iCount++); } int main(int argc, char* argv[]) { MMRESULT uTimerID = timeSetEvent(500, 10, (LPTIMECALLBACK)timer_handle, (DWORD)NULL, TIME_PERIODIC); for (int i = 0; i < 10; i ++) { Sleep(1000); } timeKillEvent(uTimerID); return 0; } |