4118500(菜青虫~) 21:09:17
VB问题 
4118500(菜青虫~) 21:09:27
我想播放光驱中的CD 
4118500(菜青虫~) 21:09:57
那么OPEN的时候是不要是填写打开光驱的盘符? 
4118500(菜青虫~) 21:10:08
可是怎样得到光驱的盘符呢? 还有,如果只有盘符也不能构成完整的文件名地址呀
只有“地址+文件名”才能播放文件呀

解决方案 »

  1.   

    如何获得系统光驱的盘符?
    其实做到这一点很简单,就是调用一个API函数:GetDriveType,具体声明如下: 
    Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long该函数返回系统驱动器类型,返回值为5即为光驱,下面这个例子仅作简单的演示,你可以做进一步的改进以用在您自己的应用程序当中Private Sub GetCDRomLetter()Dim DriveNum As Integer
    Dim DriveType
    Dim CDRom As Integer
    Dim DriveLetter As String
    Dim i As Byte
    DriveNum = 1
    Do
    DriveNum = DriveNum + 1
    DriveLetter = Chr(DriveNum + 65) + ":\"
    DriveType = GetDriveType(DriveLetter)
    If DriveType = DRIVE_CDROM Then Debug.Print DriveLetter'DRIVE_CDROM=5
    Loop Until DriveType = 1'返回值为1,已无可用驱动器End Sub 
      

  2.   

    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    Const DRIVE_CDROM = 5
    Private Sub GetCDRomLetter(path As String)Dim DriveNum As Integer
    Dim DriveType
    Dim CDRom As Integer
    Dim DriveLetter As String
    Dim i As Byte
    DriveNum = 1
    Do
    DriveNum = DriveNum + 1
    DriveLetter = Chr(DriveNum + 65) + ":\"
    DriveType = GetDriveType(DriveLetter)
    If DriveType = DRIVE_CDROM Then
        Debug.Print DriveLetter 'DRIVE_CDROM=5
        path = DriveLetter
        Exit Sub
    End If
    Loop Until DriveType = 1 '返回值为1,已无可用驱动器
    path = DriveLetter
    End SubPrivate Sub Form_Load()
    Dim a As String
    Call GetCDRomLetter(a)
    MsgBox a
    End Sub
      

  3.   

    非常好用,我试过
    如果你用的是VB。NET请这样声明API
    Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Integer