【VB开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了VB开源代码-Demo_frm.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