Working With Resource File
Lesson 2
Play Wav file that found in
Resource File
This example will show you
how to play wav file that found in Resource File, using the LoadDataIntoFile
function.
Add 1 Wav File to your resource file, and set the Wav file ID
to be 101.
Add the following code to your form:
'the API
declaration that play Wav file
Private Declare Function
sndPlaySound Lib "winmm.dll" Alias
"sndPlaySoundA"
_
(ByVal
lpszSoundName As String, ByVal uFlags As Long) As Long
'the LoadDataIntoFile function
Public Sub
LoadDataIntoFile(DataName As Integer, FileName
As String)
Dim myArray() As Byte
Dim myFile As Long
If Dir(FileName) = "" Then
myArray =
LoadResData(DataName, "CUSTOM")
myFile =
FreeFile
Open FileName For Binary Access Write
As #myFile
Put #myFile, , myArray
Close
#myFile
End If
End Sub
Private Sub Form_Load()
'copy the Wav file to
c:\tmpfile.$$$
LoadDataIntoFile 101, "c:\tmpfile.$$$"
'Play the Wav file
using the sndPlaySound API function
sndPlaySound "c:\tmpfile.$$$", 1
End Sub
Run the program. The wav file will be
played.