Using the GetSystemMetrics Function
The GetSystemMetrics function can return one of 70 or so values, depending on which you request. In each case, you pass it a single constant value, and it returns the piece of information you need.
You shouldn't need to worry about specific constants and their values if you're using the classes provided in this chapter. If you're interested, however, your best reference information for GetSystemMetrics (and its partner, SystemParametersInfo) is the MSDN CD.
To find the number of mouse buttons, for example, you might use a call like this:
lngMouseButtons = GetSystemMetrics(SM_CMOUSEBUTTONS)
and to find out whether there's a mouse with a wheel installed, you could use
fWheelMouse = GetSystemMetrics(SM_MOUSEWHEELPRESENT)
Of course, you don't have to use either of these. You can retrieve both pieces of information using the Mouse class we've provided:
Dim oMouse As New Mouse lngMouseButtons = oMouse.Buttons fWheelMouse = oMouse.WheelPresent
If you see references to “mouse wheels” throughout this chapter, don't go out looking for information on rodent transportation. This term refers to Microsoft's input device with two mouse buttons and a rubberized wheel between the buttons.
You'll find calls to GetSystemMetrics scattered throughout the classes provided with this chapter. When we gathered information for this chapter, it made more sense to group the classes based on the functionality of the information than on its source, so you'll find calls to GetSystemMetrics, and other general-purpose API calls, throughout the various classes.
In addition to API calls, you'll find the declarations for the functions and the constants they use. For example, you'll find this block of code in the declarations area of MOUSE.CLS:
Private Const SM_CXCURSOR = 13 Private Const SM_CYCURSOR = 14 Private Const SM_MOUSEPRESENT = 19 Private Const SM_SWAPBUTTON = 23 Private Const SM_CXDOUBLECLK = 36 Private Const SM_CYDOUBLECLK = 37 Private Const SM_CMOUSEBUTTONS = 43 Private Const SM_CXDRAG = 68 Private Const SM_CYDRAG = 69 Private Const SM_MOUSEWHEELPRESENT = 75 Private Declare Function GetSystemMetrics Lib "user32" _ (ByVal nIndex As Long) As Long
This set of declarations declares the API function and provides the necessary constant values needed by the class. (All the constants beginning with “SM_” will be used by GetSystemMetrics.)