void WaitForThreadExit(void)
{
DWORD dwRet;
MSG msg;
int wait_count=4;
int nExitThreadCount=0;
while(1)
{
dwRet = MsgWaitForMultipleObjects(wait_count, hArray, FALSE, INFINITE, QS_ALLINPUT);
if (dwRet == WAIT_OBJECT_0 + wait_count)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message==WM_QUIT||msg.message==WM_CLOSE)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}else if (dwRet >= WAIT_OBJECT_0 && dwRet < WAIT_OBJECT_0+ wait_count)
{
nExitThreadCount++;
if (nExitThreadCount < 4)
{
TRACE("一个线程退出了\n");
int nIndex=dwRet-WAIT_OBJECT_0;
hArray[nIndex]=hArray[wait_count-1];
hArray[wait_count-1]=NULL;
wait_count--;
}else
{
TRACE("4个线程都退出了\n");
break;
}
}else
{
DWORD dErrCode=GetLastError();
break;
}
}
}