Get a site

VC++ 6.0 ebook chapter index
Free counters!

Mouse Basics

Windows 98 can support a one-button, two-button, or three-button mouse, or it can use a joystick or light pen to mimic a mouse. In the early days, Windows applications avoided the use of the second or third buttons in deference to users who had a one-button mouse. However, the two-button mouse has become the de facto standard, so the traditional reticence to use the second button is no longer justified. Indeed, the second button is now the standard for invoking a "context menu," which is a menu that appears in a window outside the normal menu bar, or for special dragging operations. (Dragging will be explained shortly.) However, programs should not rely upon the presence of a two-button mouse.

In theory, you can determine if a mouse is present by using our old friend the GetSystemMetrics function:

fMouse = GetSystemMetrics (SM_MOUSEPRESENT) ;

The value of fMouse will be TRUE (nonzero) if a mouse is installed and 0 if a mouse is not installed. However, in Windows 98 this function always returns TRUE whether a mouse is attached or not. In Microsoft Windows NT, it works correctly.

To determine the number of buttons on the installed mouse, use

cButtons = GetSystemMetrics (SM_CMOUSEBUTTONS) ;

This function should also return 0 if a mouse is not installed. However, under Windows 98 the function returns 2 if a mouse is not installed.

Left-handed users can switch the mouse buttons using the Windows Control Panel. Although an application can determine whether this has been done by calling GetSystemMetrics with the SM_SWAPBUTTON parameter, this is not usually necessary. The button triggered by the index finger is considered to be the left button, even if it's physically on the right side of the mouse. However, in a training program, you might want to draw a mouse on the screen, and in that case, you might want to know if the mouse buttons have been swapped.

You can set other mouse parameters in the Control Panel, such as the double-click speed. From a Windows application you can set or obtain this information using the SystemParametersInfo function.

Some Quick Definitions

When the Windows user moves the mouse, Windows moves a small bitmapped picture on the display. This is called the "mouse cursor." The mouse cursor has a single-pixel "hot spot" that points to a precise location on the display. When I refer to the position of the mouse cursor on the screen, I really mean the position of the hot spot.

Windows supports several predefined mouse cursors that programs can use. The most common is the slanted arrow named IDC_ARROW (using the identifier defined in WINUSER.H). The hot spot is the tip of the arrow. The IDC_CROSS cursor (used in the BLOKOUT programs shown later in this chapter) has a hot spot in the center of a crosshair pattern. The IDC_WAIT cursor is an hourglass generally used by programs to indicate they are busy. Programmers can also design their own cursors. You'll learn how in Chapter 10. The default cursor for a particular window is specified when defining the window class structure, for instance:

wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;

The following terms describe the actions you take with mouse buttons:

On a three-button mouse, the buttons are called the left button, the middle button, and the right button. Mouse-related identifiers defined in the Windows header files use the abbreviations LBUTTON, MBUTTON, and RBUTTON. A two-button mouse has only a left button and a right button. The single button on a one-button mouse is a left button.

The Plural of Mouse Is…

And now, to demonstrate my bravery, I will confront one of the most perplexing issues in the field of alternative input devices: what is the plural of "mouse"?

Although everyone knows that multiple rodents are called mice, no one seems to have a definitive answer for what we call multiple input devices. Neither "mice" nor "mouses" sounds quite right. My customary reference—the third edition of the American Heritage Dictionary of the English Language—says that either is acceptable (with "mice" preferred), while the third edition of the Microsoft Press Computer Dictionary avoids the issue entirely.

The book Wired Style: Principles of English Usage in the Digital Age (HardWired, 1996) by the editors of Wired magazine indicates that "mouses" is preferred to avoid confusion with rodents. Doug Engelbart, who invented the mouse in 1964, is of no help at all in resolving this issue. I once asked him about the plural of mouse and so did the editors of Wired. He says he doesn't know.

Finally, with an air of high authority, the Microsoft Manual of Style for Technical Publications instructs us to "Avoid using the plural mice; if you need to refer to more than one mouse, use mouse devices." This may sound like a cop-out, but it's really quite sensible advice when neither plural sounds right. Indeed, most sentences that might require a plural for "mouse" can be recast to avoid it. For example, rather than saying "People use mice almost as much as keyboards," try "People use the mouse almost as much as the keyboard."