Chapter 9: Retrieving and Setting System Information

If  you want to write professional applications, you’ll need to be able to maintain some level of control over your users’ environments. You may want to temporarily turn off the mouse cursor or modify the Windows accessibility features. You may need to position one window at a particular location within another, requiring you to know the width of the window border. Or, in an attempt to position a window, you may need to know exactly how tall the caption bar is or how wide the vertical scrollbar is. Perhaps you want to control the state of the CapsLock or NumLock key. Perhaps you need to allow users to modify their system colors from within your application.

The goal of this chapter is to provide you with simple, easily callable classes, with appropriate properties and methods, that wrap up much of the Windows API functionality dealing with system information. In particular, you’ll find classes that supply functionality pertaining to the mouse, keyboard, accessibility functions, system memory, power status, window metrics, border metrics, system colors, and computer and operating system information. Once you’ve imported the relevant classes into your own applications, you’ll be able to determine, and often set, many system parameters that control the way Windows and your applications function. (For more information on writing and using class modules, see Chapter 5.)

Of course, this chapter is far from complete. You can obtain much more information by digging into the corners of the API. There’s plenty here to get you started, however, and the techniques we’ve used to wrap the API functionality should give you ideas for extending the tools provided here, should the need arise.

If you find this information interesting or would like to extend the classes provided here, there’s one tool you must have: Microsoft’s MSDN CD subscription. This quarterly CD provided almost all the information we used to create the tools in this chapter and is well worth the small expense. Contact Microsoft for more information about ordering this extremely useful tool, with one caveat: the CD is geared toward C/C++ programmers, and to make the best use of it, you’ll need some way to convert the information into a format you can use. Your best bet is to combine the information on the MSDN CD with Daniel Appleman’s formidable best-seller, Visual Basic Programmer’s Guide to the Win32 API (Ziff-Davis Press, 1996.) This book provides VBA-centric coverage of most of the Win32 API. Combined with the MSDN CD, you’ll have all the information you need.

Table 9.1 lists the sample files you’ll find on the CD-ROM that accompanies this book.

Table 9.1: Sample Files

File Name Description
SYSINFO.XLS Excel 97 workbook containing all the sample classes
SYSINFO.MDB Access 97 databases containing all the sample classes
SYSINFOTEST.BAS Test stub procedure
ACCESSIBILITY.CLS Accessibility class module
FONT.CLS Font information for the NonClientMetrics class
KEYBOARD.CLS Keyboard class module
MEMORYSTATUS.CLS Memory status class module
MOUSE.CLS Mouse class module
NONCLIENTMETRICS.CLS Non–client metrics class module
POWERSTATUS.CLS Power status class module
SCREEN.CLS Screen class module
SYSTEMCOLORS.CLS System colors class module
SYSTEMINFO.CLS Operating system and computer class module

© 1997 by SYBEX Inc. All rights reserved.