Access Cookbook - Ken Getz [244]
To create a similar form in your own application, follow these steps:
Import the module basSystemInfo from 11-13.MDB into your own application. This module contains all the constants, API declarations, and wrapper functions that you'll need.
Create a new form. Place an unbound text box (or checkbox, or option group; see fsubInfo for hints) on the form for each piece of information you wish to display. Set the control sources as shown in Table 11-13. The sample form, frmSystemInfo, uses an option group that lets you choose which page of the subform, fsubInfo, you'd like to see. This has nothing to do with the functionality of the sample beyond cosmetics; it just makes it easier to group the information.
Table 11-13. Control sources for text boxes on frmSystemInfo
Item
Control source
Screen resolution
=acbGetScreenX( ) & " x " & acbGetScreenY( )
Mouse installed
=acbMouseInstalled( )
Keyboard type
=acbKeyboardType( )
Memory load
=acbGetMemoryStatus(0)
Total physical memory
=acbGetMemoryStatus(1)
Available physical memory
=acbGetMemoryStatus(2)
Total page file
=acbGetMemoryStatus(3)
Available page file
=acbGetMemoryStatus(4)
Total virtual memory
=acbGetMemoryStatus(5)
Available virtual memory
=acbGetMemoryStatus(6)
Operating system version
=acbGetOSInfo(0) & "." & acbGetOSInfo(1)
Build number
=acbGetOSInfo(2)
Platform
=acbGetOSInfo(3)
Windows directory
=acbWindowsDirectory( )
System directory
=acbSystemDirectory( )
Temp path
=acbTempPath( )
Access directory
=acbAccessDirectory( )
OEM ID
=acbGetSystemStatus(0)
Page size
=acbGetSystemStatus(1)
Lowest memory address
=acbGetSystemStatus(2)
Highest memory address
=acbGetSystemStatus(3)
Active processor mask
=acbGetSystemStatus(4)
Number of processors
=acbGetSystemStatus(5)
Processor type
=acbGetSystemStatus(6)
Discussion
The functions used here employ a variety of techniques to return the requested information. In general, they query the low-level Windows API to retrieve hardware and Windows environment information. We've wrapped each low-level function in an Access function to handle data type conversions from the dynamic link libraries (DLLs) used by Windows into the format that Access can understand.
frmSystemInfo uses several functions to return information about the current computer:
Screen resolution
The acbGetScreenX and acbGetScreenY functions use the GetSystemMetrics API function to return the size of the screen in pixels. This API function can return many other details about your system, including the width of the window borders, the size of the icons, and whether a mouse is installed. To call it, just pass it one of the constants shown later, in Table 11-14; it will return the requested value to you. For example:
Public Function acbGetScreenX( )
' Retrieve the screen width in pixels.
acbGetScreenX = GetSystemMetrics(SM_CXSCREEN)
End Function
Mouse installed
Again, the GetSystemMetrics function does the work:
Public Function acbMouseInstalled( ) As Boolean
' Is a mouse installed?
acbMouseInstalled = CBool(GetSystemMetrics(SM_MOUSEPRESENT))
End Function
Keyboard type
The GetKeyboardType function provides the answers:
Public Function acbKeyboardType( )
' Retrieve information about the keyboard.
' Call GetKeyboardType with
' 0 Keyboard Type
' 1 Keyboard SubType (depends on the manufacturer)
' 2 Number of function keys
acbKeyboardType = GetKeyboardType(0)
End Function
Memory information
The GlobalMemoryStatusEx function fills in a user-defined data structure with information about the current memory load, available and total real and virtual memory, and paging space. We've wrapped all this information up in the acbGetMemoryStatus function:
Public Function acbGetMemoryStatus(intItem As Integer) As Variant
' Retrieve system memory information
' In:
' intItem: Which piece of information to retrieve
' 0: Memory load (0 to 100)
' 1: Total physical memory in bytes
' 2: Available physical memory in bytes
' 3: