'FAT32 FreeSpace
Create a new project, and add this code to Form1:
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
Private Sub Form_Load()
Dim r As Long, BytesFreeToCalller As Currency, TotalBytes As Currency
Dim TotalFreeBytes As Currency, TotalBytesUsed As Currency
'the drive to find
Const RootPathName = "C:\"
'get the drive's disk parameters
Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
'show the results, multiplying the returned
'value by 10000 to adjust for the 4 decimal
'places that the currency data type returns.
Me.AutoRedraw = True
Me.Cls
Me.Print
Me.Print " Total Number Of Bytes:", Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes"
Me.Print " Total Free Bytes:", Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes"
Me.Print " Free Bytes Available:", Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes"
Me.Print " Total Space Used :", Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
End Sub
Create a new project, and add this code to Form1:
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
Private Sub Form_Load()
Dim r As Long, BytesFreeToCalller As Currency, TotalBytes As Currency
Dim TotalFreeBytes As Currency, TotalBytesUsed As Currency
'the drive to find
Const RootPathName = "C:\"
'get the drive's disk parameters
Call GetDiskFreeSpaceEx(RootPathName, BytesFreeToCalller, TotalBytes, TotalFreeBytes)
'show the results, multiplying the returned
'value by 10000 to adjust for the 4 decimal
'places that the currency data type returns.
Me.AutoRedraw = True
Me.Cls
Me.Print
Me.Print " Total Number Of Bytes:", Format$(TotalBytes * 10000, "###,###,###,##0") & " bytes"
Me.Print " Total Free Bytes:", Format$(TotalFreeBytes * 10000, "###,###,###,##0") & " bytes"
Me.Print " Free Bytes Available:", Format$(BytesFreeToCalller * 10000, "###,###,###,##0") & " bytes"
Me.Print " Total Space Used :", Format$((TotalBytes - TotalFreeBytes) * 10000, "###,###,###,##0") & " bytes"
End Sub
解决方案 »
- 我覆盖安装了系统win2000 pro sp4 安装了vb6.0打开原来的工程运行说找不到工程或库??
- 帮帮忙啊,有分加
- 关于Treeview展开指定节点的问题!分不够可以在加呀!
- 读VB 2005 Introduce有感!
- 怎么判断引用无效?例如判断myFrm是否为Nothing?
- 用ADO添加字段,请问怎样使添加的字段可以为空(只有不到100分了)
- 请教 为什么round()函数当是5时不进位只有>5时才进。
- 难度较高!!!100分!!!
- 急急急急急急急急急急急急急
- 请问为什么 "If Adodc5.Recordset("客户名称") <> Null Then Text22.Text = Adodc5.Recordset("客户名称")"中条件是真时它也没付值呀这是怎么回事呀?
- 有问题请教
- *.db的数据库文件用什么软件可以打开呀
http://www.csdn.net/expert/topic/651/651692.xml?temp=.871258
我们使用了 GetDiskFreeSpace API 来求出磁盘大小及剩余空间大小,
在问题:如何求出磁盘大小及剩余空间大小 (更简单的 VB6 新功能)
我们使用了 FileSystemObject 来求出磁盘大小及剩余空间大小,如果网友自己曾经实际测试过这二个主题的程序码,而您的硬盘又大于 2GB 时,或许您会发现,只要大于 2GB 的部份都无法正确的显示!为什么会这样呢?这是因为目前 VB 只支持到 32 位的 Integer 资料型态,所以最大值就是 2GB!要解决这个问题,您必须改用另一个 API GetDiskFreeSpaceEx,不过,在这个 API 中,有使用了一个新的 ULARGE_INTEGER Structure,所以在声明 GetDiskFreeSpaceEx API 之前,您也必须要先声明 ULARGE_INTEGER Type:Type ULARGE_INTEGER
LowPart As Long
HighPart As Long
End TypeDeclare Function GetDiskFreeSpaceEx Lib "kernel32.dll" Alias "GetDiskFreeSpaceExA" _
(ByVal lpDirectoryName As String, _ '目录名称或磁盘代码
lpFreeBytesAvailableToCaller As ULARGE_INTEGER, _ '剩余可用空间大小 (Bytes)
lpTotalNumberOfBytes As ULARGE_INTEGER, _ '磁盘总空间大小 (Bytes)
lpTotalNumberOfFreeBytes As ULARGE_INTEGER) As Long '剩余总空间大小 (Bytes)ULARGE_INTEGER Structure 是一个 VB 预设中尚未支持的 64 位的 Integer,它的范围是从 &H0 到 &HFFFFFFFFFFFFFFFF (也就是 2 的 64 次方),它可用于所有尚未支持 64 位的 Integer 的程序语言中。它将 64 位的值切割成二个 32 位的部份,也就是 LowPart 及 HighPart。如果那一天 VB 开始支持 64 位的 Integer 资料型态,ULARGE_INTEGER Structure 就用不到了,否则,您一定要记得声明!在模组中声明了上面的 Type ULARGE_INTEGER 及 GetDiskFreeSpaceEx API 之后,我们来看看以下的范例程序: Private Sub Command1_Click()
Dim userbytes As ULARGE_INTEGER ' 目前 User 可用磁盘空间
Dim totalbytes As ULARGE_INTEGER ' 磁盘总空间
Dim freebytes As ULARGE_INTEGER ' 磁盘剩余总空间
Dim retval As Long ' GetDiskFreeSpaceEx 的返回值If Text1.Text = "" Then Text1.Text = "C"
retval = GetDiskFreeSpaceEx(Text1.Text & ":\", userbytes, totalbytes, freebytes)
'
If userbytes.LowPart < 0 Then
User 可用磁盘空间 = Format((userbytes.HighPart * (16 ^ 8)) + (userbytes.LowPart + (16 ^ 8)), "#,###")
Else
User 可用磁盘空间 = Format((userbytes.HighPart * (16 ^ 8)) + userbytes.LowPart, "#,###")
End If
'
If totalbytes.LowPart < 0 Then
磁盘总空间 = Format((totalbytes.HighPart * (16 ^ 8)) + (totalbytes.LowPart + (16 ^ 8)), "#,###")
Else
磁盘总空间 = Format((totalbytes.HighPart * (16 ^ 8)) + totalbytes.LowPart, "#,###")
End If
'
If freebytes.LowPart < 0 Then
磁盘剩余总空间 = Format((freebytes.HighPart * (16 ^ 8)) + (freebytes.LowPart + (16 ^ 8)), "#,###")
Else
磁盘剩余总空间 = Format((freebytes.HighPart * (16 ^ 8)) + freebytes.LowPart, "#,###")
End If
'
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub注意:以上的功能有以下 OS 本身的限制Windows 95 必须在 OSR2 或以后的版本才行!
Windows NT 必须在 4.0 以后的版本才行!