Created
June 1, 2011 05:30
-
-
Save thinkhy/1001826 to your computer and use it in GitHub Desktop.
Win32 Waitable Timer and MsgWaitForMultipleObjects
This file contains 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
//////////////////////////////////////////////////////////////////////////////////// | |
HANDLE hTimer; | |
LARGE_INTEGER li; | |
hTimer = CreateWaitableTimer(NULL, FALSE, NULL); | |
const int nTimerUnitsPerSecond = 10000000; | |
li.QuadPart = -(30 * nTimerUnitsPerSecond); | |
SetWaitableTimer(hTimer, &li, 0, NULL, NULL, FALSE); | |
MSG msg; | |
DWORD dwWait; | |
do | |
{ | |
dwWait = MsgWaitForMultipleObjects( | |
1, | |
&hTimer, | |
FALSE, | |
10000, | |
QS_ALLINPUT); | |
switch (dwWait) | |
{ | |
case WAIT_OBJECT_0 + 1: | |
{ | |
if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) | |
{ | |
// if (msg.message == WM_PAINT) | |
// { | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
// } | |
} | |
break; | |
} | |
case WAIT_TIMEOUT: | |
case WAIT_OBJECT_0: // 打包工具成功启动 | |
{ | |
// ::ShowWindow(hwnd, SW_HIDE); | |
break; | |
} | |
case WAIT_FAILED: | |
{ | |
return false; | |
} | |
default: | |
{ | |
while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) | |
{ | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
/* | |
CloseHandle(hTimer); | |
CloseHandle(hPipe); | |
AfxMessageBox(L"打包工具启动失败", MB_ICONERROR); | |
return false; | |
*/ | |
} | |
} | |
} while(dwWait != WAIT_OBJECT_0 | |
|| dwWait == WAIT_TIMEOUT ||dwWait == WAIT_ABANDONED); | |
AfxMessageBox(L"OK"); | |
//////////////////////////////////////////////////////////////////////////////////// | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment