用VB实现发声的几种方法
简单实用的beep命令发省
Beep 2400, 100 ‘ beep 频率,毫秒时长
调用api,打开声音文件
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
例如:
ShellExecute(me.hWnd, "open", "c:\temp\1.wav", "", "", 1)
调用api函数 mciSendString播放声音
Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
例如:
mciSendString "open " & “c:\temp\1.wav” & " alias wav", String(255, " "), 255, 0
mciSendString "play wav ",String(255, " "), 255, 0
if f_MciChkEnd() then mciSendString "close wav ",String(255, " "), 255, 0
Function f_MciChkEnd()
Dim MCIStatus As String * 255
Dim lA
f_MciChkEnd = False
lA = mciSendString("status wav mode", MCIStatus, Len(MCIStatus), 0)
If UCase(Left$(MCIStatus, 7)) = "STOPPED" Or Left$(MCIStatus, 2) = "结束" Then
f_MciChkEnd = True
end if
End Function