Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

MouseWheel

This event, introduced in Visual FoxPro 5.0, allows users of wheel-enabled devices to affect FoxPro controls.

Usage

Procedure Object.MouseWheel()
LPARAMETERS [nIndex, ] nDirection, nModifierKeys, nXCoord, nYCoord

Parameter

Value

Meaning

nIndex

Integer

Used in the rare case that the object is part of a control array.

nDirection

Numeric

Indicates the direction and magnitude of the mouse wheel movement. In VFP 5.0, the Help referred to this as "nDelta" and they changed it in the 6.0 Help to "nDirection." In either case, the parameter describes the direction with the sign of the variable—negative for backward, zero for no movement and positive for forward—and a multiple of a fixed number, dependent on the particular device, to describe the number of clicks forward or backward.

nModifierKeys

Integer

A set of bit flags to indicate whether the Shift, Alt or Control keys are used. Shift sets the number to 1, Control to 2 and Alt to 4. If more than one of the keys is used, nModifierKeys is the sum of them.

nXCoord

Integer

The x-coordinate of the mouse, relative to the current form, in the current ScaleMode.

nYCoord

Integer

The y-coordinate of the mouse, relative to the current form, in the current ScaleMode.

Microsoft, Logitech and several other vendors have recently introduced wheel-bearing mice and trackballs. While the most common purpose of the wheel is to provide for scrolling in documents longer than the screen, most Microsoft software (including, of course, Visual FoxPro) supports additional functionality. Clicking the mouse wheel in an edit box or scrolling region can allow the user alternative scrolling modes. Check out all of the native behaviors before you decide to write your own.

With the information supplied in this event, you may choose to have your controls provide their own behaviors. Use the SIGN() function to determine the direction of motion. Have the user tune your application by capturing, in some “tune-up” dialog, just what his mouse driver returns for a single mouse-wheel click. Use BITTEST() to determine which modifier keys are in use.

Example

* Example code from a test toolbar
* Three command buttons display the RGB values
* One text box shows the "nDirection" sign and magnitude
* Holding Shift, Control or Alt modifies the BackColor
* of the toolbar

LPARAMETERS nDirection, nShift, nXCoord, nYCoord
LOCAL lnIncrement

* && -1 for backward, +1 for forward
lnIncrement = SIGN(nDirection)

* Foxtools loaded in Init
LOCAL lnRed, lnGreen, lnBlue
* Foxtools function to return individual R, G, B values
=RGBComp(This.BackColor, @lnRed, @lnGreen, @lnBlue)

* nShift is, or contains, 1 - Shift
lnRed = lnRed + IIF(BITTEST(nShift,0), lnIncrement, 0)
* nShift is, or contains, 2 - Control
lnGreen = lnGreen + IIF(BITTEST(nShift,1), lnIncrement, 0)
* nShift is, or contains, 4, - Alt
lnBlue = lnBlue + IIF(BITTEST(nShift,2), lnIncrement, 0)

* Restrict the values to the range 0 - 255
lnRed = MAX(0,MIN(255,lnRed))
lnGreen = MAX(0,MIN(255,lnGreen))
lnBlue = MAX(0,MIN(255,lnBlue))

This.cmdRed.Caption = "R: " + PADL(lnRed,3,"0")
This.cmdGreen.Caption = "G: " + PADL(lnGreen,3,"0")
This.cmdBlue.Caption = "B: " + PADL(lnBlue,3,"0")

This.BackColor = RGB(lnRed, lnGreen, lnBlue)

* Display the nDirection
This.TEXT1.Value = nDirection

See Also

BitTest(), Control Arrays, MiddleClick, MouseDown, MouseMove, ScaleMode