Visual Basic Tip: 11/27/95
Play a .WAV sound file from VB.
You can play a waveform (.WAV) sound file from VB by calling the
sndPlaySound API function in the MMSYSTEM.DLL.
Declare Function sndPlaySound Lib "MMSYSTEM.DLL" (ByVal lpszSoundName$, ByVal wFlags%) As Integer
Global Const SND_SYNC = &H0000
Global Const SND_ASYNC = &H0001
Global Const SND_NODEFAULT = &H0002
Global Const SND_LOOP = &H0008
Global Const SND_NOSTOP = &H0010
SoundFile$ = "c:\windows\chimes.wav"
wFlags% = SND_ASYNC Or SND_NODEFAULT
x% = sndPlaySound(SoundFile$,wFlags%)
lpszSoundName$: The name of the sound to play. First searches the
[sounds] section of the WIN.INI file for an entry
with the name, and plays the associated waveform
sound file. If no entry by this name exists, then
it assumes the specified name is the name of a
waveform sound file. If this parameter is NULL, any
currently playing sound is stopped (0& = NULL).
wFlags% : Options using one or more of the flags:
SND_SYNC Played synchronously and the function does not
return until the sound ends.
SND_ASYNC Played asynchronously and the function returns
immediately after beginning the sound.
SND_NODEFAULT If the sound cannot be found, the function returns
silently without playing the default sound.
SND_LOOP The sound will continue to play repeatedly until
sndPlaySound is called again with the lpszSoundName$
parameter set to null. You must also specify the
SND_ASYNC flag to loop sounds.
SND_NOSTOP If a sound is playing, the function will immediately
return False without playing the requested sound.
The sndPlaySound function returns True if the sound is played,
otherwise it returns False.
Return to Phil's Web Page
Created by: Philip