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_SET_DOOR_CLOSED = &H200& 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() 'KPD-Team 2001 'URL: http://www.allapi.net/ '[email protected] Dim lRet As Long 'initialize the structure openParams.wDeviceID = 0 openParams.lpstrDeviceType = "cdaudio" 'get the device ID lRet = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, openParams) 'check for error If lRet <> 0 Then 'show error MsgBox GetMCIErrorString(lRet), vbCritical Else '开门 lRet = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal 0&)
'关门 'lRet = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, ByVal 0&) 'check for errors If lRet <> 0 Then MsgBox GetMCIErrorString(lRet), vbCritical End If 'clean up mciSendCommand openParams.wDeviceID, MCI_CLOSE, 0, ByVal 0& End Sub Private Function GetMCIErrorString(lErr As Long) As String 'create a buffer GetMCIErrorString = Space$(255) 'retrieve the error string mciGetErrorString lErr, GetMCIErrorString, Len(GetMCIErrorString) 'strip off the trailing spaces GetMCIErrorString = Trim$(GetMCIErrorString) End Function
怎样打开或关闭CD-ROM? 如果你想通过VB打开或者关闭CD-ROM,你可以向Windows Multimedia DLL发出一条相关的命令请求,但是你必须先声明DLL:在模块文件中加入以下代码: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 以下是打开CD-ROM的过程代码:retvalue = mcisendstring("set CDAudio door open", _returnstring, 127, 0) 关闭CD-ROM用以下代码:retvalue = mcisendstring("set CDAudio door closed", _returnstring, 127, 0)
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_SET_DOOR_CLOSED = &H200&
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()
'KPD-Team 2001
'URL: http://www.allapi.net/
'[email protected]
Dim lRet As Long
'initialize the structure
openParams.wDeviceID = 0
openParams.lpstrDeviceType = "cdaudio"
'get the device ID
lRet = mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE Or MCI_OPEN_SHAREABLE, openParams)
'check for error
If lRet <> 0 Then
'show error
MsgBox GetMCIErrorString(lRet), vbCritical
Else
'开门
lRet = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, ByVal 0&)
'关门
'lRet = mciSendCommand(openParams.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, ByVal 0&)
'check for errors
If lRet <> 0 Then MsgBox GetMCIErrorString(lRet), vbCritical
End If
'clean up
mciSendCommand openParams.wDeviceID, MCI_CLOSE, 0, ByVal 0&
End Sub
Private Function GetMCIErrorString(lErr As Long) As String
'create a buffer
GetMCIErrorString = Space$(255)
'retrieve the error string
mciGetErrorString lErr, GetMCIErrorString, Len(GetMCIErrorString)
'strip off the trailing spaces
GetMCIErrorString = Trim$(GetMCIErrorString)
End Function
如果你想通过VB打开或者关闭CD-ROM,你可以向Windows Multimedia DLL发出一条相关的命令请求,但是你必须先声明DLL:在模块文件中加入以下代码: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 以下是打开CD-ROM的过程代码:retvalue = mcisendstring("set CDAudio door open", _returnstring, 127, 0) 关闭CD-ROM用以下代码:retvalue = mcisendstring("set CDAudio door closed", _returnstring, 127, 0)