Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Private Declare Function sndStopSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszNull As Long, ByVal uFlags As Long) As Long
Private Const SND_MEMORY = &H4
Private Const SND_SYNC = &H0
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H2
Private Const SND_LOOP = &H8
Private Const SND_NOSTOP = &H10Private arrBound() As Byte
Private arrFired() As Byte
Private arrNoBullet() As Byte
Private Function PlaySound(ind As Integer) As Boolean
Dim r As Long
Dim uFlags As Long
uFlags = SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY
r = sndStopSound(0, SND_ASYNC)
Select Case ind
Case 0 'Fire
r = sndPlaySound(arrFired(0), uFlags)
Case 1 'Shotted
r = sndPlaySound(arrBound(0), uFlags)
Case 2 'esNoBullet
r = sndPlaySound(arrNoBullet(0), uFlags)
End Select
End FunctionPrivate Function LoadSound() As Boolean
arrBound = LoadResData("Bound", "WAVE")
arrFired = LoadResData("Fire", "WAVE")
arrNoBullet = LoadResData("NoBullet", "WAVE")
End Function
sndPlaySound(filename, SND_ASYNC Or SND_NODEFAULT )
播放wav文件Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Private Declare Function sndStopSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszNull As Long, ByVal uFlags As Long) As Long
Private Const SND_MEMORY = &H4
Private Const SND_SYNC = &H0
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H2
Private Const SND_LOOP = &H8
Private Const SND_NOSTOP = &H10Private arrBound() As Byte
Private arrFired() As Byte
Private arrNoBullet() As Byte
Private Function PlaySound(byval sFile as string) As Boolean
Dim r As Long
Dim uFlags As Long
uFlags = SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY
r = sndStopSound(0, SND_ASYNC)
r = sndPlaySound(sFile, uFlags)
End Function第二个贴子是播放资源文件里的wav
播放wav文件Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Private Declare Function sndStopSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszNull As Long, ByVal uFlags As Long) As Long
Private Const SND_MEMORY = &H4
Private Const SND_SYNC = &H0
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H2
Private Const SND_LOOP = &H8
Private Const SND_NOSTOP = &H10Private Sub PlaySound(byval sFile as string)
Dim r As Long
Dim uFlags As Long
uFlags = SND_ASYNC Or SND_NODEFAULT
r = sndStopSound(0, SND_ASYNC)
r = sndPlaySound(sFile, uFlags)
End Sub
(ByVal lpszSoundName As String, ByVal uFlags As Long) As LongPublic Sub PlayWav(sFilename As String)X& = sndPlaySound(sFilename, 1)End Sub
Private Sub Label1_Click()
timecount = 60 * 8
IeTimer1.Enabled = ValTrue
End SubPrivate Sub IeTimer1_Timer()
timecount = timecount - 1
Label1.Caption = timecount \ 60 & "分" & timecount Mod 60 & "秒"
If timecount = 60 Then
Beep
End If
If timecount = 0 Then
Beep
IeTimer1.Enabled = False
End If
End Sub我想在上面的代码中用一个自己录的WAV文件代替Beep,怎么能实现呢?请指教,多谢!
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Private Declare Function sndStopSound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszNull As Long, ByVal uFlags As Long) As Long
Private Const SND_MEMORY = &H4
Private Const SND_SYNC = &H0
Private Const SND_ASYNC = &H1
Private Const SND_NODEFAULT = &H2
Private Const SND_LOOP = &H8
Private Const SND_NOSTOP = &H10private timecount As LongPrivate Sub Beep()
Dim r As Long
Dim uFlags As Long,sFile as string sFile=app.path & "\" & "x.wav" 'your own wave file name and place the wave file under your project directory uFlags = SND_ASYNC Or SND_NODEFAULT
r = sndStopSound(0, SND_ASYNC)
r = sndPlaySound(sFile, uFlags)
End Sub
Private Sub Label1_Click()
timecount = 60 * 8
IeTimer1.Enabled = ValTrue
End SubPrivate Sub IeTimer1_Timer()
timecount = timecount - 1
Label1.Caption = timecount \ 60 & "分" & timecount Mod 60 & "秒"
If timecount = 60 Then
Beep
End If
If timecount = 0 Then
Beep
IeTimer1.Enabled = False
End If
End Sub
像下面这样写对吗?
借在哪里?sFile=app.path & "\" & "1.wav" 'your own wave file name and place the wave file under your project directory
放在你的工程目录里
app.path是你当前工程的路径自己多动动手
sFile是你存放的wave文件的路径文件名你自己把它的路径设置好了就可以了,可以不用app.path