How is sndPlaySound used?
Printable View
How is sndPlaySound used?
Code:Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Global Const SND_ASYNC = &H1
Global Const SND_NODEFAULT = &H2
Sub Playwav(file)
SoundName$ = file
wFlags% = SND_ASYNC Or SND_NODEFAULT
X% = sndPlaySound(SoundName$, wFlags%): NoFreeze% = DoEvents()
End Sub
Use PlaySound instead. It's slightly more flexible.
Code:Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Sub Command1_Click()
'Play the WAV
PlaySound "C:\MyFile.wav", 0&, &H1
End Sub
Code:'same dog different sled
'added how to stop the file from playing
' bas module code
'API Function to play the sound
'
Public Declare Function sndPlaySound Lib "winmm" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
'
' play synchronously (default)..music finishes first
Public Const SND_SYNC = &H0
' play asynchronously
Public Const SND_ASYNC = &H1
' loop the sound until next
Public Const SND_LOOP = &H8
'<<<<< form code >>>>>>>>
'this one plays and allows other events to take place
'ie form can change and music will still be playing
Private Sub Command1_Click()
Call sndPlaySound(ByVal "c:\yourfolder\yourfile.wav", SND_ASYNC)
End Sub
'to stop it you send it nothing as a parameter
Private Sub Command2_Click()
Call sndPlaySound(0,0)
End Sub