怎样在vb程序内添加声音?我想让程序在其他电脑上使用时也有声音,不许把声音文件拷过去
1个回答
展开全部
在vb外接程序管理器中可以添加资源管理器,添加后就可以在工具菜单中调用资源管理器了,打开资源管理器并添加两个自定义资源,我首先添加的是一个文本文件,编号为101,然后添加了一个wav声音文件,编号为102,用loadresdata调入内存播放的,你可以试验一下
Option Explicit
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function sndPlaySoundFromMemory Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1&
Private Const SND_MEMORY = &H4&
Private Sub Command1_Click()
Dim barr() As Byte, s As String, k As Variant
barr = LoadResData(101, "custom")
s = ""
For Each k In barr
s = s + Chr(k)
Next
MsgBox s
barr = LoadResData(102, "custom")
sndPlaySoundFromMemory barr(0), SND_ASYNC Or SND_MEMORY
End Sub
Option Explicit
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Private Declare Function sndPlaySoundFromMemory Lib "winmm.dll" Alias "sndPlaySoundA" (lpszSoundName As Any, ByVal uFlags As Long) As Long
Private Const SND_ASYNC = &H1&
Private Const SND_MEMORY = &H4&
Private Sub Command1_Click()
Dim barr() As Byte, s As String, k As Variant
barr = LoadResData(101, "custom")
s = ""
For Each k In barr
s = s + Chr(k)
Next
MsgBox s
barr = LoadResData(102, "custom")
sndPlaySoundFromMemory barr(0), SND_ASYNC Or SND_MEMORY
End Sub
更多追问追答
追问
我在使用时总向我报错,“内存不能read...”,这是怎么回事?能再说下吗?
追答
你添加过资源了吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询