谢谢了哦
如何做一个点击一个按钮就出一下声音 那个声音文件是.wav的
sndSoundPlay
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Public Sub PlaySoundFile1(ByVal FileName As String, Optional ByVal Wait As Boolean = False)
If Wait Then
Call PlaySound(FileName, 0&, SND_FILENAME)
Else
Call PlaySound(FileName, 0&, SND_ASYNC Or SND_FILENAME)
End If
End Sub
call PlaySoundFile1
在vb中实现多线程
新建一Module
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Sub main()
Load Form1
Form1.Show
End Sub
Public Sub c1()
.......
End Sub
Public Sub c2()
......
End Sub
新建一窗体
Private hthread1 As Long
Private hthread2 As Long
Private ithread1 As Long
Private ithread2 As Long
Private Sub Command1_Click()
ithread1 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c1, ByVal 0&, ByVal 0&, hthread1) --创建线程一
ithread2 = CreateThread(ByVal 0&, ByVal 0&, AddressOf c1, ByVal 0&, ByVal 0&, hthread1) --创建线程二
CloseHandle ithread1 --关闭线程一
CloseHandle ithread2 --关闭线程二
End Sub
没有这么麻烦吧!
就用一个API函数就可以,要注意一下参数。
声明如下:
Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Const SND_SYNC = &H0 同步播放
Const SND_ASYNC = &H1 异步播放
Const SND_NOSTOP = &H10 不停止当前播放的任何声音
参见MSDN
调用如下:
dim Ret as Long
Ret=PlaySound("c:\ccc.wav",0&,SND_ASYNC OR SND_NOSTOP)