VB3 How VB Can Get Windows Status Information via API CallsID: Q84556 
  | 
The Visual Basic for Windows program example below demonstrates how
you can obtain system status information similar to the information
displayed in the Windows Program Manager About box. The example
program displays the following information using the Windows API
function(s) indicated:
   ' Constants for GetWinFlags.
   Global Const WF_CPU286 = &H2
   Global Const WF_CPU386 = &H4
   Global Const WF_CPU486 = &H8
   Global Const WF_80x87 = &H400
   Global Const WF_STANDARD = &H10
   Global Const WF_ENHANCED = &H20
   Global Const WF_WINNT = &H4000
   ' Type for SystemHeapInfo.
   Type SYSHEAPINFO
      dwSize As Long
      wUserFreePercent As Integer
      wGDIFreePercent As Integer
      hUserSegment As Integer
      hGDISegment As Integer
   End Type
   Declare Function GetVersion Lib "Kernel" () As Integer
   Declare Function GetWinFlags Lib "Kernel" () As Long
   'Enter each of the following Declare statements as one, single line:
   Declare Function GetFreeSpace Lib "Kernel" (ByVal wFlags As Integer)
      As Long
   Declare Function GlobalCompact Lib "Kernel" (ByVal dwMinFree As Long)
      As Long
   Declare Function SystemHeapInfo Lib "toolhelp.dll" (shi As
      SYSHEAPINFO) As Integer
 
   Sub Form_Load ()
      Dim msg As String         ' Status information.
      Dim nl As String          ' New-line.
      nl = Chr$(13) + Chr$(10)  ' New-line.
      Show
      MousePointer = 11   ' Hourglass.
      ver% = GetVersion()
      status& = GetWinFlags()
      ' Get operating system and version.
      If status& And WF_WINNT Then
         msg = msg + "Microsoft Windows NT "
      Else
         msg = msg + "Microsoft Windows "
      End If
      ver_major$ = Format$(ver% And &HFF)
      ver_minor$ = Format$(ver% \ &H100, "00")
      msg = msg + ver_major$ + "." + ver_minor$ + nl
      ' Get CPU kind and operating mode.
      msg = msg + "CPU: "
      If status& And WF_CPU286 Then msg = msg + "80286"
      If status& And WF_CPU386 Then msg = msg + "80386"
      If status& And WF_CPU486 Then msg = msg + "80486"
      If status& And WF_80x87 Then msg = msg + " with 80x87"
      msg = msg + nl
      msg = msg + "Mode: "
      If status& And WF_STANDARD Then msg = msg + "Standard" + nl
      If status& And WF_ENHANCED Then msg = msg + "Enhanced" + nl
      ' Get free memory.
      memory& = GetFreeSpace(0)
      msg = msg + "Memory free: "
      msg = msg + Format$(memory& \ 1024, "###,###,###") + "K" + nl
      memory& = GlobalCompact(&HFFFFFFFF)
      msg = msg + "Largest free block: "
      msg = msg + Format$(memory& \ 1024, "###,###,###") + "K" + nl
      ' Get free system resources.
      ' The API SystemHeapInfo became available in Windows version 3.1.
      msg = msg + "System resources: "
      If ver% >= &H310 Then
         Dim shi As SYSHEAPINFO
         shi.dwSize = Len(shi)
         If SystemHeapInfo(shi) Then
            If shi.wUserFreePercent < shi.wGDIFreePercent Then
               msg = msg + Format$(shi.wUserFreePercent) + "%"
            Else
               msg = msg + Format$(shi.wGDIFreePercent) + "%"
            End If
         End If
      Else
         msg = msg + "n/a"
      End If
      MsgBox msg, 0, "About " + Caption
      MousePointer = 0
   End Sub
 Additional query words: 2.00 3.00 3.10 286 386 486
Keywords          : kbcode kbWndw 
Version           : 1.00 2.00 3.00
Platform          : WINDOWS 
Issue type        : 
Last Reviewed: June 4, 1999