Option Explicit
'Put 4 command buttons on a form (NOT in an array).
'Sound files used: Put in the project's folder, AND the resource file.
'"101-tada.wav" Res ID 101 - formerly "C:\Windows\Media\tada.wav"
'"102-nudge.wav" Res ID 102 - formerly "C:\Program Files\MSN Messenger\nudge.wav"
'"103-wmpaud1.wav" Res ID 103 - formerly "C:\WINDOWS\Help\Tours\WindowsMediaPlayer\Audio\Wav\wmpaud1.wav"
'"104-Mwiip.wav" Res ID 104 - external source. Find your own :-)
'Note the different ways you can call PlaySound & sndPlaySound, depending
'on whether you want to pass a number or string.
'PlaySound.
'Pass a String reference to lpszName.
Private Declare Function PlaySoundString Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
'Pass a Long Resource reference to lpszName.
Private Declare Function PlaySoundResource Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As Long, ByVal hModule As Long, ByVal dwFlags As Long) As Long
'sndPlaySound.
'Pass a String reference to lpszSoundName.
Private Declare Function sndPlaySoundString Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
'Pass a Long Resource reference to lpszSoundName.
Private Declare Function sndPlaySoundLong Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As Long, ByVal uFlags As Long) As Long
'Required constants.
Const SND_ASYNC = &H1 'Play asynchronously.
Const SND_FILENAME = &H20000 'Name is a file name.
Const SND_PURGE = &H40 'Release memory.
Const SND_RESOURCE = &H40004 'Name is a resource name or atom.
Private Sub Form_Load()
'Add proper captions to the command buttons.
Command1.Caption = "PlaySound - Resource"
Command2.Caption = "PlaySound - HDD"
Command3.Caption = "sndPlaySound - Resource"
Command4.Caption = "sndPlaySound - HDD"
End Sub
Private Sub Command1_Click()
'PlaySound. Resource file. 104-Mwiip.wav
Dim RetVal As Long
'Reference nothing and purge memory.
RetVal = PlaySoundResource(0, App.hInstance, SND_PURGE)
'Reference the res file and ... Top Of The Pops ...
RetVal = PlaySoundResource(104, App.hInstance, SND_RESOURCE Or SND_ASYNC)
End Sub
Private Sub Command2_Click()
'PlaySound. HDD file. 101-tada.wav
Dim RetVal As Long
'Reference nothing and purge memory.
RetVal = PlaySoundString("", App.hInstance, SND_PURGE)
'Reference the res file and ... Top Of The Pops ...
RetVal = PlaySoundString(App.Path & "\101-tada.wav", App.hInstance, SND_FILENAME Or SND_ASYNC)
End Sub
Private Sub Command3_Click()
'sndPlaySound. Resource file. 103-wmpaud1.wav
Dim RetVal As Long
'Reference nothing and purge memory.
RetVal = sndPlaySoundLong(0, SND_PURGE)
'Reference the res file and ... Top Of The Pops ...
RetVal = sndPlaySoundLong(103, SND_RESOURCE Or SND_ASYNC)
End Sub
Private Sub Command4_Click()
'sndPlaySound. HDD file. 102-nudge.wav
Dim RetVal As Long
'Reference nothing and purge memory.
RetVal = sndPlaySoundString("", SND_PURGE)
'Reference the HDD file.
RetVal = sndPlaySoundString(App.Path & "\102-nudge.wav", SND_FILENAME Or SND_ASYNC)
End Sub