已解决问题
满意答案 好评率:100%
![](https://ucc.alicdn.com/nxvio7gfxsj4a/developer-article563187/20241020/8d2696501bcb4b6e8b9ea3dbfe4eefc3.jpeg?x-oss-process=image/resize,w_1400/format,webp)
Option Explicit
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long
Dim r As Long
Dim BytesFreeToCalller As Currency
Dim TotalBytes As Currency
Dim TotalFreeBytes As Currency
Dim TotalBytesUsed As Currency
Dim RootPathName As String
Dim DiskName As String
Dim BytesFreeToCalller As Currency
Dim TotalBytes As Currency
Dim TotalFreeBytes As Currency
Dim TotalBytesUsed As Currency
Dim RootPathName As String
Dim DiskName As String
Private Sub exit_Click()
Unload Me
End Sub
Private Sub Form_Load()
Timer1.Interval = 100 '每0.1秒发生一次Timer事件
Drive1.Drive = "c:"
checkdiskform.Left = (Screen.Width - checkdiskform.Width) / 2
checkdiskform.Top = (Screen.Height - checkdiskform.Height) / 2
checkdiskform.Top = (Screen.Height - checkdiskform.Height) / 2
End Sub
Private Sub Timer1_Timer()
RootPathName = Drive1.Drive
RootPathName = Mid(RootPathName, 1, 2)
DiskName = StrConv(Left(RootPathName, 1), vbUpperCase)
RootPathName = Mid(RootPathName, 1, 2)
DiskName = StrConv(Left(RootPathName, 1), vbUpperCase)
On Error GoTo errhandler
Dir1.Path = Drive1.Drive
Dir1.Path = Drive1.Drive
Dim x As String
Label1 = DiskName + "盘的容量信息"
'调用API函数获取容量信息
r = GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
'用FORMAT函数输出习惯的数据 显示格式
total.Text = Format$(TotalBytes * 10000, "###,###,###,##0")
free.Text = Format$(TotalFreeBytes * 10000, "###,###,###,##0")
used.Text = Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0")
Exit Sub
'调用API函数获取容量信息
r = GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
'用FORMAT函数输出习惯的数据 显示格式
total.Text = Format$(TotalBytes * 10000, "###,###,###,##0")
free.Text = Format$(TotalFreeBytes * 10000, "###,###,###,##0")
used.Text = Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0")
Exit Sub
本文转自9pc9com博客,原文链接: http://blog.51cto.com/215363/955731
如需转载请自行联系原作者