您的位置:首页 > 移动开发 > Objective-C

WaitForMultipleObjects()函数

2015-07-23 19:50 781 查看






列表:一个主消息循环,内含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

}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: