mciSendString MciSendCommand Private Const MCI_OPEN = &H803 Private Const MCI_OPEN_TYPE = &H2000& Private Const MCI_OPEN_SHAREABLE = &H100& Private Const MCI_SET = &H80D Private Const MCI_SET_DOOR_OPEN = &H100& Private Const MCI_CLOSE = &H804 Private Type MCI_OPEN_PARMS dwCallback As Long wDeviceID As Long lpstrDeviceType As String lpstrElementName As String lpstrAlias As String End Type Private Declare Function mciSendCommand Lib "winmm.dll" Alias "mciSendCommandA" (ByVal wDeviceID As Long, ByVal uMessage As Long, ByVal dwParam1 As Long, ByRef dwParam2 As Any) As Long Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long Dim openParams As MCI_OPEN_PARMS Private Sub Form_Load() Dim rc As Long openParams.wDeviceID = 0 openParams.lpstrDeviceType = "cdaudio" rc = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, openParams) If rc <> 0 Then MsgBox GetMCIErrorString(rc), vbCritical Else rc = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal 0&) If rc <> 0 Then MsgBox GetMCIErrorString(rc), vbCritical End If mciSendCommand openParams.wDeviceID, MCI_CLOSE, 0, ByVal 0& End Sub Private Function GetMCIErrorString(lErr As Long) As String GetMCIErrorString = Space$(255) mciGetErrorString lErr, GetMCIErrorString, Len(GetMCIErrorString) GetMCIErrorString = Trim$(GetMCIErrorString) End Function
Declare Function Beep Lib "kernel32" ( _ ByVal dwFreq As Long, _ ByVal dwDuration As Long) As Long
不过playsound是播文件的
我想知道有没有更高级的如
指定声音的频率什么的
MciSendCommand
Private Const MCI_OPEN = &H803
Private Const MCI_OPEN_TYPE = &H2000&
Private Const MCI_OPEN_SHAREABLE = &H100&
Private Const MCI_SET = &H80D
Private Const MCI_SET_DOOR_OPEN = &H100&
Private Const MCI_CLOSE = &H804
Private Type MCI_OPEN_PARMS
dwCallback As Long
wDeviceID As Long
lpstrDeviceType As String
lpstrElementName As String
lpstrAlias As String
End Type
Private Declare Function mciSendCommand Lib "winmm.dll" Alias "mciSendCommandA" (ByVal wDeviceID As Long, ByVal uMessage As Long, ByVal dwParam1 As Long, ByRef dwParam2 As Any) As Long
Private Declare Function mciGetErrorString Lib "winmm.dll" Alias "mciGetErrorStringA" (ByVal dwError As Long, ByVal lpstrBuffer As String, ByVal uLength As Long) As Long
Dim openParams As MCI_OPEN_PARMS
Private Sub Form_Load()
Dim rc As Long
openParams.wDeviceID = 0
openParams.lpstrDeviceType = "cdaudio"
rc = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, openParams)
If rc <> 0 Then
MsgBox GetMCIErrorString(rc), vbCritical
Else
rc = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal 0&)
If rc <> 0 Then MsgBox GetMCIErrorString(rc), vbCritical
End If
mciSendCommand openParams.wDeviceID, MCI_CLOSE, 0, ByVal 0&
End Sub
Private Function GetMCIErrorString(lErr As Long) As String
GetMCIErrorString = Space$(255)
mciGetErrorString lErr, GetMCIErrorString, Len(GetMCIErrorString)
GetMCIErrorString = Trim$(GetMCIErrorString)
End Function
ByVal dwFreq As Long, _
ByVal dwDuration As Long) As Long