大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
VC++中不占CPU的延时方法:
网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、成都小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了香坊免费建站欢迎大家使用!
int CtestThreadDlg::DelayTime(int m)//参数为延时秒数 { HANDLE hTimer = NULL; HANDLE hT[2]; LARGE_INTEGER liDueTime; liDueTime.QuadPart = m *(-100000000) / 10; hTimer = CreateWaitableTimer(NULL, TRUE, _T("theTimer")); hT[0] = hTimer; if (!hTimer) { return 1; } if (!SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, FALSE)) { CloseHandle(hTimer); return 2; } DWORD lBusy; do { lBusy = MsgWaitForMultipleObjects(1, hT, FALSE, 0xffff, QS_ALLINPUT); const MSG msg; GetMessage((LPMSG) &msg, NULL, 0, 0); DispatchMessage(&msg); } while (lBusy == (WAIT_OBJECT_0 + 1)); CloseHandle(hTimer); return 0; }