VB 弹出和关闭光驱

来源:百度知道 编辑:UC知道 时间:2024/06/17 12:38:55
如何弹出和关闭光驱托盘

新建工程,添加一个窗体、三个按钮
按钮1:打开光驱。按钮2:关闭光驱。按钮3:退出
代码如下:
Option Explicit
Private Declare Function CDdoor Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Dim state1 As Boolean

Private Sub Command1_Click()
'打开光驱
state1 = True
Call CDdoor("set CDAudio door open", 0, 0, 0)
End Sub

Private Sub Command2_Click()
'关闭光驱
state1 = False
Call CDdoor("set CDAudio door closed", 0, 0, 0)
End Sub

Private Sub Command3_Click()
End
End Sub