Compartilhar via


Using Windows Messages to Manage Waveform Audio Playback

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

You can send a variety of Windows Embedded CE messages to a window procedure function to manage waveform audio playback. The following table shows these messages.

Message Description

MM_WIM_CLOSE

Sent when the waveOutClose or the waveInClose function closes a device.

MM_WIM_DATA

Sent when the device driver finishes with a data block that is sent by the waveOutWrite or the waveInAddBuffer function.

MM_WIM_OPEN

Sent when the waveOutOpen or the waveInOpen function opens a device.

The MM_WIM_DATA message is the most useful message in the preceding table. When MM_WIM_DATA signals a completed data block, you can clean up and free that data block. Unless you need to allocate memory or initialize variables, you probably do not need to process the MM_WIM_OPEN message or the MM_WIM_CLOSE message.

Like other Windows-based messages, these Windows-based messages have a wParam parameter and an lParam parameter that are associated with them. The wParam parameter always specifies a handle to the open waveform audio output device. For the MM_WIM_DATA message, lParam specifies a pointer to a WAVEHDR structure. This structure identifies a completed data block. The MM_WIM_CLOSE and MM_WIM_OPEN messages do not use lParam.

The following code example shows how to process the MM_WIM_DATA message.

// WndProc-Main window procedure 
LRESULT FAR PASCAL WndProc (HWND hWnd, UINT msg, WPARAM wParam, 
                            LPARAM lParam) 
{ 
  switch (msg) 
  { 
    case MM_WIM_DATA: 
      // A waveform audio data block has been played and can now be 
      // freed. 
      waveOutUnprepareHeader ((HWAVEOUT)wParam, (LPWAVEHDR)lParam, 
                              sizeof (WAVEHDR)); 
      // Free hData memory 
      waveOutClose ((HWAVEOUT)wParam); 

      break; 
  } 

  return DefWindowProc (hWnd, msg, wParam, lParam); 
}

The preceding example assumes that the application does not play multiple data blocks, so it can close the output device after playing a single data block.

See Also

Concepts

Using the Waveform Audio Interface