获得磁盘类型.frm

来自「Windows API函数,希望大伙有用哦」· FRM 代码 · 共 57 行

FRM
57
字号
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   2175
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3210
   LinkTopic       =   "Form1"
   ScaleHeight     =   2175
   ScaleWidth      =   3210
   StartUpPosition =   3  '窗口缺省
   Begin VB.ListBox List1 
      Height          =   1500
      Left            =   180
      TabIndex        =   0
      Top             =   510
      Width           =   2775
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "当前计算机上的磁盘:"
      Height          =   180
      Left            =   300
      TabIndex        =   1
      Top             =   150
      Width           =   1800
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Private Sub Form_Load()
Dim I As Integer
Dim Ret As Long '函数返回值
Dim DiskType As String '磁盘类型
For I = 65 To 90 '字符 A ~ Z 的 ASCII 码
  DiskType = ""
  Ret = GetDriveType(Chr$(I) & ":\") '传入磁盘代号
  Select Case Ret
    Case 2
      DiskType = "软盘"
    Case 3
      DiskType = "硬盘"
    Case 4
      DiskType = "网路磁盘"
    Case 5
      DiskType = "光盘"
  End Select
  If DiskType <> "" Then List1.AddItem vbTab & Chr$(I) & ":\" & DiskType
Next I
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?