WaitForMultipleObjects()函数

来源:互联网 发布:动圈动铁圈铁 知乎 编辑:程序博客网 时间:2024/05/18 19:38

惊恐列表:一个主消息循环,内含MsgWaitForMultipleObjects()


DWORD nWaitCount;
HANDLE hWaitArray[4];
BOOL quit;
int exitCode;


while (!quit)
{
MSG msg;
int rc;
rc = MsgWaitForMultipleObjects(
nWaitCount, hWaitArray, FALSE,
INFINITE, QS_ALLINPUT);
if (rc == WAIT_OBJECT_0 + nWaitCount)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{//get next message in queue
if (msg.message == WM_QUIT)
{
quit = TRUE;
exitCode = msg.wParam;
break;
}///end if
TranslateMessage(&msg);//将虚拟键消息转换为字符消息
DispatchMessage(&msg);//消息传递给操作系统,然后操作系统去调用我们的回调函数


}//end while
}
else if (rc >= WAIT_OBJECT_0 && rc < WAIT_OBJECT_0 + nWaitCount)
{
int nIndex = rc - WAIT_OBJECT_0;
/*we now know that the handle at array position nIndex was signaled .we
would have had to keep track of what those handle mean to decide what to do next*/
}
else if (rc == WAIT_TIMEOUT)
{
}
else if (rc >= WAIT_ABANDONED_0 && rc < WAIT_ABANDONED_0 + nWaitCount)
{
int nIndex = rc - WAIT_ABANDONED_0;
//a thread died that owned a mutex
}
else
{
//something went wrong
}


}

0 0
原创粉丝点击