Microsoft KB Archive/247036

From BetaArchive Wiki
Knowledge Base

How To Add Sound to Form Using the Microsoft Multimedia Control

Article ID: 247036

Article Last Modified on 6/29/2004


  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 6.0 Professional Edition

This article was previously published under Q247036


This article demonstrates how to add sound, or .wav files, to a form.


Although you can use the SET BELL TO command to play a waveform file, you do not have control over the file once it starts. That is, you cannot stop, pause, or resume the waveform file. By using the Microsoft Multimedia Control version 6, you can play a waveform file when the form is opened or whenever you wish to add sound.

Because you have control over the waveform file, it is not necessary to have the Multimedia control visible. All actions can be controlled through code.

  1. In the Tools menu, under Options, click the Controls tab. Click ActiveX Controls, scroll down the list and select Microsoft Multimedia Control version 6, and then click OK.
  2. Create a new form.
  3. On the Form Controls toolbar, click the View Classes button, and then select ActiveX Controls.
  4. Click the Multimedia control and add it to the form.
  5. Select the Multimedia control and change the Name property to MCI. Change the Visible property to .F.
  6. Open the Init event of the Multimedia control and add the following code:

    * Set properties needed by MCI to open.
    THISFORM.MCI.NOTIFY = .T.       && Pause
    THISFORM.MCI.Shareable = .F.
    THISFORM.MCI.DeviceType = "WaveAudio"
    THISFORM.MCI.RecordEnabled = .T.
    THISFORM.MCI.RecordMode = 0
    THISFORM.MCI.StopEnabled = .T.
    THISFORM.MCI.FileName = GETFILE("wav")
    * Open the MCI WaveAudio device.
  7. Add a Command button and change the caption to Stop.
  8. In the click event of the Stop button, add this code:

  9. In the Destroy event of the form, add this code:

  10. Add another Command button and change the caption to Rewind.
  11. In the click event of the Rewind button, add this code:


    This is just to show how you can replay the waveform file.

    Run the form. If you have a valid waveform file, enter the path and name in the Thisform.MCI.FileName property in the Init event of the control instead of using the GETFILE() function. Click on the Stop button to stop the waveform file, then click on the Restart button to resume playing the waveform file at the same position.

(c) Microsoft Corporation 2000, All Rights Reserved. Contributions by Dean Christopher, Microsoft Corporation.

Keywords: kbhowto kbcodesnippet kbcontainer kbctrl KB247036