void CALLBACK TimerFunc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD systemTick )
{
printf("TimerId= 0x%x. SystemTick=%dms\n", nTimerid, systemTick);
}
DWORD TimeCreater(void *arg)
{
DWORD nTimerId1 = SetTimer(NULL, 1, 1000, TimerFunc);
printf("nTimerId1=0x%x.\n", nTimerId1);
DWORD nTimerId2 = SetTimer(NULL, 2, 1200, TimerFunc);
printf("nTimerId2=0x%x.\n", nTimerId2);
MSG msg;
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
//获取并分发消息
while (GetMessage(&msg, NULL, 0, 0))
{
if (msg.message == WM_TIMER) //0x113
{
printf("OnTimer,wp=ID:%x,lp=%x.\n",msg.wParam,msg.lParam );
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
int main(void)
{
CreateThread(NULL, 0, TimeCreater, NULL, 0, NULL);
return 0;
}
[vc] win32中使用定时器
于 2022-10-29 09:51:31 首次发布