'要生成程序才有效
'播放资源文件文件中的声音
'点击vb菜单-工具-资源编辑器,用鼠标拉宽,倒数第二个按钮,把你的wav文件添加进去,类型名为"WAVE",标识号为"MySound",注意都要带上双引号,然后保存资源文件,例子及代码如下,要生成程序才有效:
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_ASYNC& = &H1
Private Const SND_NODEFAULT& = &H2
Private Const SND_RESOURCE& = &H40004
Dim hInst As Long
Dim sSoundName As String
Dim lFlags As Long
Dim lRet As Long
Private Sub Form_Load()
hInst = App.hInstance
sSoundName = "MySound"
lFlags = SND_RESOURCE + SND_ASYNC + SND_NODEFAULT
lRet = PlaySound(sSoundName, hInst, lFlags)
End Sub
其实我不想用同样的代码回答相同的问题的,这种问题我回答好几个了,你提问的时候页面下方应该列举了部分类似的已解决的问题的
温馨提示:答案为网友推荐,仅供参考