VB播放资源文件文件中的声音

来源:百度文库 编辑:神马文学网 时间:2024/04/26 07:38:37
VB 提供的方法使我们可以很容易地使用资源文件中的字符、图片等资源。我们可以用以下方法播放资源文件中的wav 声音:
首先,在你的资源文件的源文件(RC) 文件加入下面一行:
MySound WAVE c:\music\vanhalen.wav
然后将其编译为RES 文件。最后使用下面的声明及代码:
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 Command1_Click()
hInst = App.hInstance
sSoundName = "MySound"
lFlags = SND_RESOURCE + SND_ASYNC + _ SND_NODEFAULT
lRet = PlaySound(sSoundName, hInst, lFlags)
End Sub本篇文章来源于 网络天空教程网 www.wangluosky.cn 原文出处:http://www.wangluosky.cn/show.asp?id=1661