|
3/7/2002 9:46:19 PM
|
Avg. Rating: 3 by 3 Users
|
Code for VB 6.0
Plop down a form, add two buttons, call one cmdCDOpen and the other CDClose.
Copy/paste in the following code:
Option Explicit
Private 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
Private Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Const DRIVE_CDROM = 5
Private Sub cmdCDOpen_Click()
Dim Ret As Long
Dim RetStr As String
Ret = MCISendString("set cd1 door open wait", RetStr, 127, 0)
End Sub
Private Sub cmdCDClose_Click()
Dim Ret As Long
Dim RetStr As String
Ret = MCISendString("set cd1 door closed wait", RetStr, 127, 0)
End Sub
Private Sub Form_Load()
Dim Ret As Long
' Replace e with the drive letter of your CD Rom
Ret = MCISendString("open e:\ type cdaudio alias cd1", 0&, 0, 0)
End Sub
|
Now, run the project and click button one (cmdCDOpen). Your CDRom drive should pop open, assuming it's drive E. Now button 2 (cmdCDClose) and it should close.
Basically what you're doing is setting the door property of the CDRom to open or closed.
Oh, and if you're feeling inventive, you can use the GetDriveTypeA function (mapped above) looping through the drives (I believe the proper syntax is GetDriveTypeA("e:\") - returning a long specifying drive type) until one returns a value equal to DRIVE_CDROM, and then set that alias to cd1 in the form_load method.
I'd stick in more info, but this is all the source I have left from when I was looking into it last year...
(Oh, and what's a guy have to do to use <PRE> tags?)
|