vb获取内存信息?
1个回答
展开全部
'新建窗体
'在窗体里放个 Label1 和 Timer1 并复制下面的内容即可
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 DisplayMemory()
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)
Label1.Caption = "入栈大小:" & 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 Form_Load()
Me.Height = 4000
Me.Width = 2750
Me.Label1.Height = Me.Height
Me.Label1.Width = Me.Width
Me.Top = (Screen.Height - Me.Height) / 2
Me.Left = (Screen.Width - Me.Width) / 2
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
DisplayMemory
End Sub
大雅新科技有限公司
2024-11-19 广告
2024-11-19 广告
这方面更多更全面的信息其实可以找下大雅新。深圳市大雅新科技有限公司从事KVM延长器,DVI延长器,USB延长器,键盘鼠标延长器,双绞线视频传输器,VGA视频双绞线传输器,VGA延长器,VGA视频延长器,DVI KVM 切换器等,优质供应商,...
点击进入详情页
本回答由大雅新科技有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询