⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo_frm.frm

📁 Visual.Basic.NET实用编程百例-47.6M.zip
💻 FRM
字号:
VERSION 5.00
Begin VB.Form form1 
   Caption         =   "获取磁盘空间"
   ClientHeight    =   2175
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   3600
   LinkTopic       =   "Form1"
   ScaleHeight     =   2175
   ScaleWidth      =   3600
   StartUpPosition =   3  'Windows Default
   Begin VB.DriveListBox DrvSelect 
      Height          =   300
      Left            =   240
      TabIndex        =   0
      Top             =   120
      Width           =   3015
   End
   Begin VB.Label lblSpaceFree 
      Height          =   375
      Left            =   120
      TabIndex        =   2
      Top             =   1320
      Width           =   3015
   End
   Begin VB.Label lblTotalSpace 
      Height          =   375
      Left            =   120
      TabIndex        =   1
      Top             =   720
      Width           =   3015
   End
End
Attribute VB_Name = "form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'   API声明
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 Form_Load()
    GetDriveInfo
End Sub

'   选中一个驱动器时
Private Sub drvSelect_Change()
    GetDriveInfo
End Sub

'   获取磁盘剩余空间信息并显示在相应的标签中
Private Function GetDriveInfo()
Dim sDrive As String
Dim lBytes As Long
Dim lMBFree As Double
Dim lMBTotal As Double
Dim lSecPerClust As Long    '   扇区每簇
Dim lBytePerSect As Long    '   字节每扇区
Dim lNumFreeClust As Long   '   空白簇的数目
Dim lTotalNumClust As Long  '   簇的总数
    
    '   获取盘符
    sDrive = Left$(DrvSelect.Drive, 1)
    sDrive = sDrive & ":\"
    '   调用API函数返回剩余空间
    lBytes = GetDiskFreeSpace(sDrive, lSecPerClust, lBytePerSect, lNumFreeClust, lTotalNumClust)
    '   转换以兆为单位
    lMBFree = lSecPerClust * lBytePerSect
    lMBFree = lMBFree * lNumFreeClust / 1024 / 1024
    lMBTotal = lSecPerClust * lBytePerSect
    lMBTotal = lMBTotal * lTotalNumClust / 1024 / 1024
    '   显示信息
       lblTotalSpace.Caption = " 磁盘大小:" & lMBTotal
    lblSpaceFree.Caption = " 可用空间:" & lMBFree
End Function

Private Sub lblNumFreeClust_Click()

End Sub

⌨️ 快捷键说明

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