如何让VB小程序发出声音?
我自己用VB做了个小游戏,可它没有声音,我想回点声音进去,当游戏发生某一个动作时,程序会发出某种对应的声音。比如飞机游戏,打子弹是一种声音,打中飞机又是一种声音。请高手指...
我自己用VB做了个小游戏,可它没有声音,我想回点声音进去,当游戏发生某一个动作时,程序会发出某种对应的声音。比如飞机游戏,打子弹是一种声音,打中飞机又是一种声音。请高手指教!
抱歉,ixusi的答案看不懂,有没有简单点的? 展开
抱歉,ixusi的答案看不懂,有没有简单点的? 展开
展开全部
建立一个模块,代码如下
用Playwav(wav声音的路径名)就可以发出声音了..
'
' playWav(filepath)
'
#If Win32 Then
Public Declare Function sndPlaySound& Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long)
#Else
Public Declare Function sndPlaySound% Lib "mmsystem.dll" (ByVal lpszSoundName As String, ByVal uFlags As Integer)
#End If 'WIN32
Global Const SND_SYNC = &H0
Global Const SND_ASYNC = &H1
Global Const SND_NODEFAULT = &H2
Global Const SND_LOOP = &H8
Global Const SND_NOSTOP = &H10
' *** pathWavFiles is a var with the subDir where
' the sound files are stored
Public Sub PlayWav(SoundName As String)
Dim tmpSoundName As String
Dim wFlags%, X%
tmpSoundName = pathWavFiles & SoundName
wFlags% = SND_ASYNC Or SND_NODEFAULT
X% = sndPlaySound(tmpSoundName, wFlags%)
End Sub
用Playwav(wav声音的路径名)就可以发出声音了..
'
' playWav(filepath)
'
#If Win32 Then
Public Declare Function sndPlaySound& Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long)
#Else
Public Declare Function sndPlaySound% Lib "mmsystem.dll" (ByVal lpszSoundName As String, ByVal uFlags As Integer)
#End If 'WIN32
Global Const SND_SYNC = &H0
Global Const SND_ASYNC = &H1
Global Const SND_NODEFAULT = &H2
Global Const SND_LOOP = &H8
Global Const SND_NOSTOP = &H10
' *** pathWavFiles is a var with the subDir where
' the sound files are stored
Public Sub PlayWav(SoundName As String)
Dim tmpSoundName As String
Dim wFlags%, X%
tmpSoundName = pathWavFiles & SoundName
wFlags% = SND_ASYNC Or SND_NODEFAULT
X% = sndPlaySound(tmpSoundName, wFlags%)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询