Advanced Accessibility Features

The Windows operating system provides a number of accessibility features. In Windows 9x and Windows NT 4.0 and later users can set Accessibility Options from the Control Panel. These next sections will describe how to access those system settings and use them in your program design.

Windows Versions

Before we get into system settings and Accessibility Options, I need to emphasize that not all accessibility options are available to all versions of Windows. In this section you can assume that unless otherwise noted, the settings are valid for Windows 95, Windows 98, Windows NT 4, and Windows NT 5. Where exceptions occur, in the sample programs I've added the Microsoft SysInfo Control 6.0 component to the project and added the control to the form. This allows me to check and make sure we're running on a system that supports the given Accessibility setting, as follows:

Dim nOS  As Integer Dim nVer As Integer Const WINDOWS_95 As Integer = 1 Const WINDOWS_NT As Integer = 2 Const VER_95_NT4 As Integer = 4 With SysInfo1     nOS = .OSPlatform     nVer = .OSVersion End With ' If Windows 95, Windows 98, or Windows NT 5.0 If (nOS = WINDOWS_95 And nVer >= VER_95_NT4) Or _     (nOS = WINDOWS_NT And nVer > VER_95_NT4) Then     ' Check accessibility setting End If 

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.

GetSystemMetrics

The GetSystemMetrics function is used to determine system metrics and configuration settings. The Visual Basic Declare statement looks like this:

Declare Function GetSystemMetrics Lib "user32" _     (ByVal nIndex As Long) As Long 

The nIndex parameter takes a constant that specifies which system metric to get. The return value depends on the nIndex parameter.

The ShowSounds metric

In Windows, the user can set the ShowSounds option on the Accessibility Options property sheet, available from the Control Panel. Setting this option indicates that the user wants to see a visual indication of sounds that occur as part of applications and the operating system. You'll want to check this option in your application and provide visual indications if the ShowSounds option is True.

Const SM_SHOWSOUNDS As Long = 70 If GetSystemMetrics(SM_SHOWSOUNDS) Then     ' Enable visual indicators. End If 

One method of providing visual indications of the information the sound is conveying is to use the FlashWindow function, discussed below.

Line borders

To set the proper border width and height around a control or image (as discussed in the "Size" section earlier), you would call GetSystemMetrics with the following constants:

Const SM_CXBORDER As Long = 5 Const SM_CYBORDER As Long = 6 

GetSystemMetrics will return the width and height measurements in pixels.

FlashWindow

The FlashWindow function does just what it says: it flashes the title bar of a window. If a window is active it flashes inactive, if a window is inactive it flashes active. FlashWindow also flashes the window's taskbar icon. This function is a visual means of attracting attention to a particular window on the screen. The Declare statement for FlashWindow is as follows:

Declare Function FlashWindow Lib "user32" _     (ByVal hwnd As Long, ByVal dwflags As Long) As Long 

You also need to declare whatever constants you'll want to use for the dwflags parameter.

Public Const FLASHW_STOP      As Long = 0 Public Const FLASHW_CAPTION   As Long = &H1& Public Const FLASHW_TRAY      As Long = &H2& Public Const FLASHW_ALL       As Long = FLASHW_CAPTION Or FLASHW_TRAY Public Const FLASHW_TIMER     As Long = &H4& Public Const FLASHW_TIMERNOFG As Long = &HC& 

The FLASHW constants have the following meanings:

  • FLASHW_STOP: stops the window from flashing and restores it to its original state

  • FLASHW_CAPTION: flashes the title bar on the window

  • FLASHW_TRAY: flashes the button for the given window on the taskbar

  • FLASHW_ALL: flashes the title bar and the taskbar button

  • FLASHW_TIMER: flashes continuously until the FLASHW_STOP flag is set

  • FLASHW_TIMERNOFG: flashes continuously as long as the window is in the background

NOTE


These flags are actually valid only in Windows 98 and Windows NT 5. In earlier versions of Windows, the second parameter of the FlashWindow call is a Boolean value that determines whether the window should flash (True) or return to its original state (False). However, you don't have to check for the Windows version to use the above flags. Any flag you set other than FLASHW_STOP will be interpreted as True and the window will flash.

The FlashWindowEx Function

The Microsoft Platform SDK includes a function named FlashWindowEx. This function is similar to FlashWindow but it offers much more functionality. FlashWindowEx is part of the Microsoft Platform SDK, which you can download from Microsoft's Web site. FlashWindowEx is available only for Windows 98 and Windows NT 5. The Declare statement for FlashWindowEx looks like this:

Declare Function FlashWindowEx Lib "user32" Alias "FlashWindowEx" _     (ByVal pfwi As tFLASHWINFO) As Long 

You specify the function parameters in a UDT, declared as follows:

Type tFLASHWINFO     cbSize    As Long     hwnd      As Long     dwFlags   As Long     uCount    As Long     dwTimeout As Long End Type 

The first variable in the UDT, cbSize, contains the size of the UDT, Len(cbSize). The next variable contains the window handle for the window you want to flash. The next variable, dwFlags, contains one of the FALSHW flags defined above. The variable uCount specifies the number of times you want to window to flash. The variable dwTimeout contains the rate, in milliseconds, at which you want the window to flash. If you set dwTimeout to 0, the default cursor blink rate will be used.

I've put an example of using this function in the Sound sample. I placed the call within a timer loop so that the window will flash more than once depending on the speed of the system. You can use different types of timing and looping mechanisms if you want the window to flash more than once, but be very careful if you do this. Certain rates of flashing can cause seizures in users suffering from epilepsy. I'm actually not terribly comfortable with the loop I put into the Sounds sample because I haven't placed any restrictions on the actual speed. A flash rate below two hertz is recommended.



Ltd Mandelbrot Set International Advanced Microsoft Visual Basics 6. 0
Advanced Microsoft Visual Basic (Mps)
ISBN: 1572318937
EAN: 2147483647
Year: 1997
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net