diskfree.frm

来自「如何读取磁盘的空间及可用空间。」· FRM 代码 · 共 126 行

FRM
126
字号
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "如何读取磁盘的空间及可用空间"
   ClientHeight    =   2220
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4155
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   ScaleHeight     =   2220
   ScaleWidth      =   4155
   StartUpPosition =   2  '屏幕中心
   Begin VB.OptionButton OptDW 
      Caption         =   "单位 MB"
      Height          =   255
      Index           =   2
      Left            =   2640
      TabIndex        =   7
      Top             =   840
      Width           =   1095
   End
   Begin VB.OptionButton OptDW 
      Caption         =   "单位 KB"
      Height          =   255
      Index           =   1
      Left            =   1440
      TabIndex        =   6
      Top             =   840
      Width           =   1095
   End
   Begin VB.OptionButton OptDW 
      Caption         =   "单位 Byte"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   5
      Top             =   840
      Value           =   -1  'True
      Width           =   1215
   End
   Begin VB.DriveListBox Drive1 
      Height          =   300
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   1815
   End
   Begin VB.Label lblFree 
      AutoSize        =   -1  'True
      Height          =   180
      Left            =   1080
      TabIndex        =   4
      Top             =   1680
      Width           =   90
   End
   Begin VB.Label lblTotal 
      AutoSize        =   -1  'True
      Height          =   180
      Left            =   1080
      TabIndex        =   3
      Top             =   1320
      Width           =   90
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "可用空间:"
      Height          =   180
      Left            =   120
      TabIndex        =   2
      Top             =   1680
      Width           =   810
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "磁盘空间:"
      Height          =   180
      Left            =   120
      TabIndex        =   1
      Top             =   1320
      Width           =   810
   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 GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long

Private Sub Drive1_Change()
    Space
End Sub

Private Sub Form_Load()
    Drive1_Change
End Sub

Sub Space()
    Dim Sectors As Long, Bytes As Long, Free As Long, Total As Long
    Dim FreeKB As Long, TotalKB As Long

    GetDiskFreeSpace Left(Drive1.Drive, 2) & "\", Sectors, Bytes, Free, Total
            
If OptDW(0).Value = True Then
    FreeKB = Bytes * Sectors * Free
    TotalKB = Bytes * Sectors * Total
End If

If OptDW(1).Value = True Then
    FreeKB = Bytes * Sectors * Free / 1024
    TotalKB = Bytes * Sectors * Total / 1024
End If

If OptDW(2).Value = True Then
    FreeKB = Bytes * Sectors * Free / 1024 / 1024
    TotalKB = Bytes * Sectors * Total / 1024 / 1024
End If
    lblFree = FreeKB
    lblTotal = TotalKB
End Sub

Private Sub OptDW_Click(Index As Integer)
    Space
End Sub

⌨️ 快捷键说明

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