用vb怎样实现单击一个按钮触发一个声音文件
发布网友
发布时间:2024-10-17 20:21
我来回答
共3个回答
热心网友
时间:2024-10-17 20:58
Public Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long '声明API函数
'声明常量 下面是这个函数的dwFlags参数的常用值
Const SND_SYNC = &H0 '声音同步播放
Const SND_ASYNC = &H1 '声音非同步播放
Const SND_NODEFAULT = &H2 '如果声音文件不存在也不产生错误
Const SND_FILENAME = &H20000 '声音是文件类型
r = PlaySound( "D:\示例.wav", 0&, SND_ASYNC Or AND_FILENAME Or SND_NODEFAULT)
写这么明白 应该了解了吧
热心网友
时间:2024-10-17 20:58
Public Function MediaPlayer(ByVal Controls As WindowsMediaPlayer, ByVal File, Optional Volume = 50, Optional ByVal Visible = 0)
Controls.Visible = Visible
Controls.settings.Volume = Volume
Controls.URL = File
Controls.Controls.play
End Function
'以上放到模块中
添加一个windowsmediaplayer控件
调用MediaPlayer,方法如下
Private Sub Form_Load()
MediaPlayer WindowsMediaPlayer1, "1.mp3", 100, 0 '控件名,文件路径,音量最大100,0隐藏或1显示控件
End Sub
热心网友
时间:2024-10-17 21:05
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 ' play asynchronously
Private Sub Command1_Click()
PlaySound "C:\WINDOWS\Media\ding.wav", 0, SND_ASYNC
End Sub