|
p; Case Else
lbldrivetype.Text = " "
End Select
'''' 得到卷标名称
retVolume1 = New String(Chr(0), 255)
retFSNbuffer = New String(Chr(0), 255)
x = GetVolumeInformation(buff, retVolume1, Len(retVolume1), retSerial, retMaxLength, retFlag, retFSNbuffer, Len(retFSNbuffer))
''''retVolume = retVolume & Chr(0)
lblFileSystem.Text = retFSNbuffer
lblvolume.Text = retVolume1
If lblvolume.Text = "" Then
lblvolume.Text = "无卷标"
End If
'''' 计算磁盘剩余空间、已用空间和总空间
x = GetDiskFreeSpace(buff, lppercluster, lpBytesPerSector, lpfree, lptotal)
freespace = lpfree * lpBytesPerSector * lppercluster
totalspace = lptotal * lpBytesPerSector * CDbl(lppercluster)
''''totalspace = totalspace * 10
lblUnusedSpace.Text = CStr(freespace) & "字节 " & CStr(Int(freespace / 1024 / 1024)) & " MB"
lblTotalVolume.Text = CStr(totalspace) & " 字节 " & CStr(Int(totalspace / 1024 / 1024)) & " MB"
lblUsedSpace.Text = CStr(totalspace - freespace) & " 字节 " & CStr(Int((totalspace - freespace) / 1024 / 1024)) & " MB"
lblintro.Text = "驱动器" & Combo1.Text
End Sub
'''' 窗体启动时,自动将当前系统上的磁盘添加到Combo控件中
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim x As Integer
Dim i As Short
Dim buff As String
For i = 65 To 90
buff = Chr(i) & ":\"
x = GetDriveType(buff)
If x > 1 Then
Combo1.Items.Add(Chr(i))
End If
Next
Combo1.Text = "C"
Call Combo1_SelectedIndexChanged(Combo1, New System.EventArgs())
End Sub
■ 运行程序
单击菜单“调试|启动”或单击 图标运行程序。
小结
我们通过使用这三个GetDriveType(),etVolumeInformation(),etDiskFreeSpace()API函数来得到有关磁盘的信息。其中,GetDriveType()函数用于获得有关磁盘驱动器类型的信息;GetVolumeInformation()函数用于获得磁盘卷标的一些信息;GetDiskFreeSpace()用于获得磁盘剩余空间和总空间信息。
上一页 [1] [2] [VB.NET程序]定制VB.NET控件编程之拦截击键动作 [VB.NET程序]VB.NET VS C#. [VB.NET程序]VB.NET 中调用浏览目录对话框 [VB.NET程序]VB.NET and C# 语法比较手册 [VB.NET程序]VB.NET 拖动无边框的窗体 [VB.NET程序]C# to VB.NET 翻译器 [VB.NET程序]101 VB.NET Applications 读书笔记(1) [VB.NET程序]vb.net 程序设计规范(1) [VB.NET程序]vb.net 存取数据库中的图片 [VB.NET程序]VB.NET Data Types
|