System Parameters & Accessibility Info Using the
SystemParametersInfo API.
Determine the Version of Windows
The SystemParametersInfo API can query and set a
wealth of system parameters. A few of them, such as the coordinates of the
visible screen, keyboard repeat rate, alignment of menus, screen saver start
delay,... are shown in the following screen shot.
This program shows how to retrieve and set many of the accessibility
features - Windows extensions that make it easier for people with disabilities
to use computers. These features effect the behavior of the system, no matter
what application is running.
For example, they allow a high contrast display mode to aid folks with impaired
visual acuity or the ability to control the mouse pointer using the numeric key
pad. This sample demonstrates nearly 100 different settings and there are many
more. See MSDN for the full set.
Also shown here is how to determine the version and service pack of Windows that
is running using GetVersionEx.
Download Source Code
The sample contains two chunks of code. A class module that provides the
accessibility functionality and a form that contains code that I was too lazy
to incorporate into the class module. Both chunks call the SystemParametersInfo
API so I talk will about the class module.
The class provides a number of Get and
Let properties allowing you to read and set the system values. When
you click the Accessiblity button, calls are made to the Get procedures.
To set the value, you will need to invoke the corresponding Let procedure. The
code is there but I have left the call for you to implement.
Many of the properties are operating system specific. See the code for details
and specifics on what the underlying value is used for. The class module offers
a RaiseError property that, if set true, will raise an error if the
property being processed is not available on the current OS. Setting this
property False suppresses error messages.
The SystemParametersInfo function requires four parameters: 1) a constant,
beginning with SPI_, indicating the value to set or read, 2) A long
integer containing the value to be set, 3) the address of a variable or data
structure that is used to pass information back to you and 4) a value that
tells the function how you want it to broadcast information about the changes
you made. It can apply your changes for your current session only or write them
to the registry so they are permanent. You can also have the function instruct
all other running applications. This is the approach used in the class module.
Most of the code is very straight forward and repetitive. A quick look at the
class module will reveal all the details. This is a very powerful API and is
certainly worth getting familiar with.
Download the source code and run it. The form will display the a number of
common system parameters. Open the Immediate window and click the Accessibility
button. The values of accessibility features will be printed.
|