for (;;){
dwRet = MsgWaitForMultipleObjects(4,hMultipleEvent,FALSE,INFINITE,QS_POSTMESSAGE);
switch (dwRet){
case WAIT_OBJECT_0://data timer event
ResetEvent(hDataTimerEvent); SendData(...);
case WAIT_OBJECT_0 + 1://begin play
ResetEvent(m_hBeginPlay);
if (m_bStarted==FALSE){
//just indicate the state of starting, not necessarily means beginning of play
//because there maybe no program to play.
m_bStarted = TRUE;
}
break;
case WAIT_OBJECT_0 + 2://end play
if (m_bStarted==TRUE){
m_bStarted = FALSE;
}
ResetEvent(m_hEndPlay);
break;
case WAIT_OBJECT_0 + 3://terminate the thread
timeKillEvent(mmDataTimer);
CloseHandle(hDataTimerEvent);
return 0;
case WAIT_OBJECT_0 + 4://message being posted by other thread been received
break;
default:
SetBSErrorCode(BSERR_WAIT_ERROR);
return 0xFFFFFFFF;
}
}