返回列表 发帖

VB win7 下查系统内存大小

Private Type LARGE_INTEGER
LowPart As Long
HighPart As Long
End Type
Private Type MEMORYSTATUSEX
dwLength As Long
dwMemoryLoad As Long
ullTotalPhys As LARGE_INTEGER
ullAvailPhys As LARGE_INTEGER
ullTotalPageFile As LARGE_INTEGER
ullAvailPageFile As LARGE_INTEGER
ullTotalVirtual As LARGE_INTEGER
ullAvailVirtual As LARGE_INTEGER
ullAvailExtendedVirtual As LARGE_INTEGER
End Type
Private Declare Function GlobalMemoryStatusEx Lib "kernel32.dll" (ByRef lpBuffer As MEMORYSTATUSEX) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Sub Command4_Click()
Dim MemStat As MEMORYSTATUSEX

Dim TotalPhys As Currency
Dim AvailPhys As Currency

Dim POPSize As Currency

Dim TotalPageFile As Currency
Dim AvailPageFile As Currency

Dim TotalVirtual As Currency
Dim AvailVirtual As Currency
With MemStat
MemStat.dwLength = Len(MemStat)
GlobalMemoryStatusEx MemStat
POPSize = .dwLength

TotalPhys = Int(LargeIntToCurrency(.ullTotalPhys) / 1024 ^ 2)
AvailPhys = Int(LargeIntToCurrency(.ullAvailPhys) / 1024 ^ 2)

TotalPageFile = Int(LargeIntToCurrency(.ullTotalPageFile) / 1024 ^ 2)
AvailPageFile = Int(LargeIntToCurrency(.ullAvailPageFile) / 1024 ^ 2)

TotalVirtual = Int(LargeIntToCurrency(.ullTotalVirtual) / 1024 ^ 2)
AvailVirtual = Int(LargeIntToCurrency(.ullAvailVirtual) / 1024 ^ 2)

Text1.Text = "入栈大小:" & POPSize & " Bytes" & vbCrLf & _
"物理内存大小:" & TotalPhys & "MB" & vbCrLf & _
"已用物理内存:" & TotalPhys - AvailPhys & "MB" & vbCrLf & _
"可用物理内存:" & Int((AvailPhys / TotalPhys) * 100) & "%" & vbCrLf & _
"可用物理内存:" & AvailPhys & "MB" & vbCrLf & vbCrLf & _
"虚拟内存大小:" & TotalVirtual & "MB" & vbCrLf & _
"已用虚拟内存:" & TotalVirtual - AvailVirtual & "MB" & vbCrLf & _
"可用虚拟内存:" & Int((AvailVirtual / TotalVirtual) * 100) & "%" & vbCrLf & _
"可用虚拟内存:" & AvailVirtual & "MB" & vbCrLf & vbCrLf & _
" 总计:" & TotalPageFile & "MB" & vbCrLf & _
" 已用:" & TotalPageFile - AvailPageFile & "MB" & vbCrLf & _
" 可用:" & AvailPageFile & "MB" & vbCrLf & vbCrLf & _
"-------------------------" & vbCrLf & _
"已经使用了: " & .dwMemoryLoad & "%"
Me.Caption = "内存:" & .dwMemoryLoad & "%"
End With
End Sub

Private Function LargeIntToCurrency(liInput As LARGE_INTEGER) As Currency
CopyMemory LargeIntToCurrency, liInput, LenB(liInput)
LargeIntToCurrency = LargeIntToCurrency * 10000
End Function


Private Sub Command2_Click()
End
End Sub
宁做真小人,不做伪君子

返回列表