Windows defines three messages for wave output devices, as described in Table A.
Table A: Windows wave-out messages
| Message | Description |
|---|---|
| MM_WOM_OPEN | The device has been opened. |
| MM_WOM_CLOSE | The device has been closed. |
| MM_WOM_DONE | The device has finished playing |
Of these messages, you'll usually care only about MM_WOM_DONE, which tells you when the buffer has finished playing. You need to know when the buffer is finished so you can perform cleanup chores. The MM_WOM_DONE message is sent either when the sound finishes normally or when the sound is interrupted. (To stop playback of the sound once it's started, call the waveOutReset function.)
As we mention in the accompanying article, you can use a callback function rather than having Windows send messages to your window procedure. According to the Multimedia Programmer's Reference (MMEDIA.HLP), the notification messages sent to the callback function have slightly different names: WOM_OPEN, WOM_CLOSE, and WOM_DONE, respectively. It doesn't matter which set of constants you use, though, because they contain exactly the same values.
class TForm1 : public TForm
{
// things omitted
private:
void OnWaveDone(TMessage& msg);
public:
__fastcall TForm1(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(
MM_WOM_DONE, TMessage, OnWaveDone)
END_MESSAGE_MAP(TForm)
};
Finally, you need to define the OnWaveDone function in your source unit. The
empty OnWaveDone function is as follows:
void TForm1::OnWaveDone(TMessage& msg)
{
}