In the process of programming often to do a data cycle, such as playing music needs to loop to the buffer to write data, at this time the more common method is to build a thread to do things, but sometimes do not want to create multi-threading can use Microsoft provides PeekMessage method, easy to use, As follows
while(Waveoutunprepareheader (hwaveout) hwaveout, LPWAVEHDR,sizeof(WAVEHDR))! =mmsyserr_noerror) { //Loop Clear Buffer If successful means playback is complete//Loop The following statement if it has not finished playing if(bexit) Break;//let loops also respond to messagesMSG message; if(::P eekmessage (&message,null,0,0, Pm_remove)) {:: TranslateMessage (&message); ::D Ispatchmessage (&message); } }
This way, you can not block the Windows message loop, remove messages from the message queue and manually forward, over
Use of PeekMessage in MFC, non-blocking message loops