In
the 16-bit world of Windows, the global memory and user information was obtained using the GetFreeSpace and GetFreeSystemResources
APIs. Under Win32, these were dropped and replaced with the GlobalMemoryStatus API.
This demo is a quickie, showing how to retrieve the memory
information of the system and display it in a label control array. Combined with other system information-based calls, a concise
summary of the users current environment can be displayed. |
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Type MEMORYSTATUS
dwLength As Long
dwMemoryLoad As Long
dwTotalPhys As Long
dwAvailPhys As Long
dwTotalPageFile As Long
dwAvailPageFile As Long
dwTotalVirtual As Long
dwAvailVirtual As Long
End Type
Private Declare Sub GlobalMemoryStatus Lib "kernel32" _
(lpBuffer As MEMORYSTATUS)
Private Sub Form_Load()
Dim MS As MEMORYSTATUS
MS.dwLength = Len(MS)
GlobalMemoryStatus MS
'divide the memory variables by 1024 (nkb)
'to obtain the size in kilobytes
Label1(0).Caption = Format$(MS.dwMemoryLoad, "###,###,###,###") & " % used"
Label1(1).Caption = Format$(MS.dwTotalPhys / 1024, "###,###,###,###") & " Kbyte"
Label1(2).Caption = Format$(MS.dwAvailPhys / 1024, "###,###,###,###") & " Kbyte"
Label1(3).Caption = Format$(MS.dwTotalPageFile / 1024, "###,###,###,###") & " Kbyte"
Label1(4).Caption = Format$(MS.dwAvailPageFile / 1024, "###,###,###,###") & " Kbyte"
Label1(5).Caption = Format$(MS.dwTotalVirtual / 1024, "###,###,###,###") & " Kbyte"
Label1(6).Caption = Format$(MS.dwAvailVirtual / 1024, "###,###,###,###") & " Kbyte"
End Sub
Private Sub Command1_Click()
Unload Me
End Sub
|