Results 1 to 17 of 17

Thread: Eject/Close a cd?

Threaded View

  1. #17
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    This will do it. You could change it just to accept either a listbox or combobox, but I made it do either.
    VB Code:
    1. Public Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal cchBuffer As Long, ByVal lpzBuffer As String) As Long
    2. Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal lpzDrive As String) As Long
    3.  
    4. Public Const DRIVE_CDROM As Long = 5
    5.  
    6. Public Sub AddCDDrives(ByRef ctlListOrCombo As Control)
    7.    Dim strBuffer As String
    8.    Dim lngLength As Long
    9.    Dim astrDrives As Variant
    10.    Dim i As Long
    11.    If (TypeOf ctlListOrCombo Is ComboBox) Or (TypeOf ctlListOrCombo Is ListBox) Then
    12.       'make a buffer
    13.       strBuffer = Space$(128)
    14.       'get the drive letters
    15.       lngLength = GetLogicalDriveStrings(Len(strBuffer), strBuffer)
    16.       'trim off the last null char
    17.       strBuffer = Left$(strBuffer, lngLength - 1)
    18.       'break the return into separate drives
    19.       astrDrives = Split(strBuffer, vbNullChar)
    20.       ctlListOrCombo.Clear
    21.       'go through each drive to see if it's a cdrom, and add it if so
    22.       For i = 0 To UBound(astrDrives)
    23.          If GetDriveType(astrDrives(i)) = DRIVE_CDROM Then ctlListOrCombo.AddItem astrDrives(i)
    24.       Next i
    25.    End If
    26. End Sub
    27.  
    28. 'usage
    29. AddCDDrives drivelistbox
    30. 'or
    31. AddCDDrives drivecombobox
    Last edited by Kaverin; Aug 14th, 2001 at 01:26 PM.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width