VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   1545
   ClientLeft      =   7725
   ClientTop       =   4575
   ClientWidth     =   2520
   LinkTopic       =   "Form1"
   ScaleHeight     =   1545
   ScaleWidth      =   2520
   Begin VB.CommandButton cmdOpenClose 
      Caption         =   "&Open/Close"
      Height          =   465
      Left            =   120
      TabIndex        =   2
      Top             =   900
      Width           =   2100
   End
   Begin VB.ComboBox cboCDDrives 
      Height          =   315
      Left            =   105
      TabIndex        =   1
      Text            =   "#caption#"
      Top             =   375
      Width           =   2190
   End
   Begin VB.Label lblCDDrives 
      AutoSize        =   -1  'True
      Caption         =   "CD Drives Present On this Pc:"
      Height          =   195
      Left            =   90
      TabIndex        =   0
      Top             =   135
      Width           =   2130
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

' Win32 API call to find the type of a drive (i.e. Hard drive, floppy etc).
Private Declare Function GetDriveType Lib "kernel32" Alias _
"GetDriveTypeA" (ByVal nDrive As String) As Long

' Win32 API call to open/close the cd drive.
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

' variable to keep track whether the drive is to be opened(true) or closed(false)
Private blnOpenRequest As Boolean

Private Sub Form_Load()
    Dim intLoopCounter As Integer
    
    ' Loop through the letters A-Z (using their ascii numbers), for
    ' each letter found, check the drive type using the above api call.
    For intLoopCounter = 65 To 90

        If (GetDriveType(Chr(intLoopCounter) & ":\") = 5) Then
            cboCDDrives.AddItem Chr(intLoopCounter) & ":\"
        End If
        
    Next intLoopCounter
    
    ' Set the initial drop down list value to the 1st entry.
    cboCDDrives.ListIndex = 0
    blnOpenRequest = True
End Sub

Private Sub cmdOpenClose_Click()

    ' Depending on the form-level variable, use the mcisendstring() call to open or close the selected drive.
    Select Case blnOpenRequest
    Case True
        mciSendString "open " & Left(Trim(cboCDDrives.Text), 1) & ": type cdaudio alias CurrentChosenDrive", vbNullString, 0, 0
        mciSendString "set CurrentChosenDrive door open", vbNullString, 0, 0

        blnOpenRequest = False
    Case False
        mciSendString "open " & Left(Trim(cboCDDrives.Text), 1) & ": type cdaudio alias CurrentChosenDrive", vbNullString, 0, 0
        mciSendString "set CurrentChosenDrive door closed", vbNullString, 0, 0
        
        blnOpenRequest = True
    End Select

End Sub

