[Previous] [TOC] [Next]

SystemParametersInfo

The SystemParametersInfo function provides access to many of the Windows system settings. I'll go over a few of the settings that are most relevant to accessibility development. But first, let's take a look at the Visual Basic declaration of this function:

Declare Function SystemParametersInfo Lib "user32" _
      Alias "SystemParametersInfoA" (ByVal iAction As Long, _
      ByVal iParam As Long, pvParam As Any, _
      ByVal fWinIni As Long) As Long

If you don't understand what's happening in this Declare statement, don't worry about it. I'll explain enough to allow you to use it effectively in your programs. Just remember that all public Declare statements must be placed in a standard module (BAS file) in your Visual Basic project.

NOTE


Declaring an argument As Any as we did in our Declare statement goes against the standards established by The Mandelbrot Set (International) Limited (TMS) and as outlined in Appendix A. The parameter is declared As Any here because the return type of that parameter is dependent on the input. However, the preferred method, when practical, would be to create a different Declare statement for each possible return value. For example, if you were going to call SystemParametersInfo to retrieve information that would be returned as a Long, your Declare statement would look something like this:
  Declare Function WinLongSystemParametersInfo Lib "user32" _
      Alias "SystemParametersInfoA" (ByVal iAction As Long, _
      ByVal iParam As Long, pvParam As Long, ByVal fWinIni As Long) _
      As Long

Notice also the prefix Win on the function declaration. This also is a TMS standard. However, in the samples in this chapter I've left the prefix off the declarations for clarity: you can see the exact name of the DLL functions, as well as the parameter names, and can look them up on Microsoft's Web site or in Visual Studio's online Help if you want more information.

Visual Basic Declare Statements For System DLLs

Visual Basic ships with a utility called the API Viewer. This utility, located in the Common\Tools\Winapi folder on the Visual Basic CD, reads in a text file filled with Visual Basic Declare statements, Type definitions, and Constant declarations for the Win32 API. You can search for the statement you want, then copy and paste it into your application. If you want to really understand how to declare functions from C language DLLs, I suggest you take a look at the chapters in this book by Phil Ridley (Chapter 10) and Peet Morris (Chapter 11).

The settings for the function parameters for SystemParametersInfo depend on what system setting you're querying for. The first parameter in the SystemParametersInfo function requires a numeric constant.

Keyboard preference

The first constant setting we'll use is SPI_GETKEYBOARDPREF, which is defined as follows:

Const SPI_GETKEYBOARDPREF As Long = 68

Specifying SPI_GETKEYBOARDPREF as the first parameter in the SystemParametersInfo function indicates that we're querying the system as to whether the user prefers the keyboard to the mouse. The user specifies this setting by selecting Accessibility Options from the Control Panel, then selecting the Show Extra Keyboard Help In Programs option on the Keyboard property page.

NOTE


This option is not available in Windows NT 4.

The second and fourth parameters of SystemParametersInfo, iParam and fWinIni, should be set to 0. The third parameter, pvParam, returns True if the user has selected keyboard preference, False otherwise. So your call would look something like this:

Dim bUseKeyboard As Boolean

  If SystemParametersInfo(SPI_GETKEYBOARDPREF, 0, _
                          bUseKeyboard, 0) Then
      ' Enable and display keyboard shortcuts.
  End If

You can see an example of this function in the Keyboard sample.

High contrast

The High Contrast option is useful when checking color settings. The user sets this display option by selecting Accessibility Options from the Control Panel, clicking the Display tab, and selecting the Use High Contrast check box. The user sets this option to display a system-defined set of colors that provide a high amount of contrast. This option is especially useful to users who are colorblind. If this option is set, it is an indication to your application that it should be using system colors and hiding all background images.

NOTE


This option is not available in Windows NT 4.

To find this setting, you need to declare the following user-defined type (UDT) in a module in your project.

Type tHIGHCONTRAST
      cbSize            As Long
      dwflags           As Long
      lpszDefaultScheme As String
  End Type

You next define the system constants:

Public Const SPI_GETHIGHCONRAST As Long = 66
  Public Const HCF_HIGHCONTRASTON As Long = &H1&

After declaring the SystemParametersInfo function, you make your call as follows:

Dim thc     As tHIGHCONTRAST
  Dim lReturn As Long

  thc.cbSize = Len(thc)
  lReturn = SystemParametersInfo(SPI_GETHIGHCONTRAST, Len(thc), _
                                 thc, 0)

  If thc.dwflags And HCF_HIGHCONTRASTON Then
      ' High contrast option is on.
  Else
       ' High contrast option is off.
  End If

You can see this function in the ColorOpt2 sample. In that sample, if the high contrast option is on when the application starts, the background picture is turned off by default.

Screen readers

Windows 9x and Windows NT 5 have the ability to determine whether a screen reader device is connected to the computer. You can capture this information by calling SystemParametersInfo with the SPI_GETSCREENREADER option, as follows.

Public Const SPI_GETSCREENREADER As Long = 70

  Dim bScreenReader As Boolean

  lReturn = SystemParametersInfo(SPI_GETSCREENREADER, 0, _
                                 bScreenReader, 0)

  If bScreenReader Then
      ' Screen reader detected; turn off the background and
      ' ensure that all graphic indicators have text explanations.
  Else
      ' No screen reader detected.
  End If

Show sounds

The SystemParametersInfo function can be used to determine the ShowSounds setting, but the GetSystemMetrics function is the preferred method, so we'll save this discussion for the GetSystemMetrics section below.

[Previous] [TOC] [Next]