Created
March 18, 2011 06:46
-
-
Save thinkhy/875701 to your computer and use it in GitHub Desktop.
演示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
// 等待打包工具初始化成功,等待时间为10秒 | |
DWORD dwWait = WAIT_FAILED; | |
MSG msg; | |
do | |
{ | |
dwWait = MsgWaitForMultipleObjects( | |
1, | |
&hEvent, | |
TRUE, | |
5000, | |
QS_POSTMESSAGE); | |
switch (dwWait) | |
{ | |
case WAIT_OBJECT_0 + 1: | |
{ | |
if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) | |
{ | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
break; | |
} | |
case WAIT_OBJECT_0: // 打包工具成功启动 | |
{ | |
::ShowWindow(hwnd, SW_HIDE); | |
break; | |
} | |
default: | |
{ | |
CloseHandle(hEvent); | |
CloseHandle(hPipe); | |
AfxMessageBox(L"打包工具启动失败", MB_ICONERROR); | |
return false; | |
} | |
} | |
} while(dwWait != WAIT_OBJECT_0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Refer to blog of Raymond Chen: http://blogs.msdn.com/b/oldnewthing/archive/2005/02/17/375307.aspx