1个回答
展开全部
可以这样的解决你的问题!!一个list控件
Option Explicit
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Sub Form_Load()
Dim nType As Long, S As String, sDrive As String
Dim pos As Integer
S = String(256, Chr(0))
GetLogicalDriveStrings Len(S), S
Do
pos = InStr(S, Chr(0))
sDrive = Left(S, pos - 1)
If Len(sDrive) = 0 Then Exit Do
S = Mid(S, pos + 1)
nType = GetDriveType(sDrive)
List1.AddItem Left(sDrive, 2) & " = " & GetDriveName(nType)
Loop Until pos <= 0
End Sub
Function GetDriveName(ByVal nType As Long)
Select Case nType
Case 1
GetDriveName = "目录不存在"
Case DRIVE_REMOVABLE
GetDriveName = "抽取式磁盘"
Case DRIVE_FIXED
GetDriveName = "硬盘"
Case DRIVE_REMOTE
GetDriveName = "远程(网络)储存装置"
Case DRIVE_CDROM
GetDriveName = "光盘驱动器"
Case DRIVE_RAMDISK
GetDriveName = "RAM Disk"
Case Else
GetDriveName = "无从判断"
End Select
End Function
Option Explicit
Private Const DRIVE_REMOVABLE = 2
Private Const DRIVE_FIXED = 3
Private Const DRIVE_REMOTE = 4
Private Const DRIVE_CDROM = 5
Private Const DRIVE_RAMDISK = 6
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Sub Form_Load()
Dim nType As Long, S As String, sDrive As String
Dim pos As Integer
S = String(256, Chr(0))
GetLogicalDriveStrings Len(S), S
Do
pos = InStr(S, Chr(0))
sDrive = Left(S, pos - 1)
If Len(sDrive) = 0 Then Exit Do
S = Mid(S, pos + 1)
nType = GetDriveType(sDrive)
List1.AddItem Left(sDrive, 2) & " = " & GetDriveName(nType)
Loop Until pos <= 0
End Sub
Function GetDriveName(ByVal nType As Long)
Select Case nType
Case 1
GetDriveName = "目录不存在"
Case DRIVE_REMOVABLE
GetDriveName = "抽取式磁盘"
Case DRIVE_FIXED
GetDriveName = "硬盘"
Case DRIVE_REMOTE
GetDriveName = "远程(网络)储存装置"
Case DRIVE_CDROM
GetDriveName = "光盘驱动器"
Case DRIVE_RAMDISK
GetDriveName = "RAM Disk"
Case Else
GetDriveName = "无从判断"
End Select
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询