Easily Play a WAV File
This source code will easily allow you to play a WAV file from within your Visual Basic application WITHOUT using an ActiveX Control. The two most amazing facts about this source code that amazed me were:
• The value for the "flag." I had absolutely no idea what to do for the flag. But I took a good guess at it, and I got it!
• It will actually play the WAV file from the Visual Basic environment (you don't need to compile it to hear the sound).
Assumes
1) Create one (1) CommandButton Control on the Form, and set the Name property to "cmdSound" (minus the quotes).
Rate Easily Play a WAV File
(6(6 Vote))
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Sub PlayWav(Filename As String)
sndPlaySound (Filename), &H80
End Sub
Private Sub cmdSound_Click()
PlayWav "C:\WINDOWS\Media\Chord.wav"
'Chord.wav is a file that comes along with both
'Windows 95 and 98 Operating Systems. If your
'system is missing this file, specify a different WAV.
End Sub
'Now, press F5, or the Run button in the Visual Basic
'Environment, and then click the button. If you enjoy
'this source code, please let me know by posting feedback.
'Thanks!
Easily Play a WAV File Comments
No comments yet — be the first to post one!
Post a Comment