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.

AMouseObj()

This function, added in VFP 6, gives you information about the current position of the mouse pointer.

Usage

nFoundSomething = AMouseObj( Info [, nRelativeToForm ] )
</tr> </table> `AMouseObj()` recognizes any VFP form or control, along with some parts of the development environment. If the mouse is outside VFP or over one of the unrecognized objects, the function returns 0 and leaves the array alone. For no reason we can think of, Browses are among the unrecognized objects even though they're really grids internally. The function fills the first two array elements with object references to the object itself and the object's container. The third and fourth elements contain the coordinates (in pixels) of the mouse position relative to the container. However, if the optional second parameter is passed, the second element gets a reference to the containing form, no matter how deep in the hierarchy the control is. In that case, the point returned in the third and fourth elements is instead relative to the form.

Parameter

Value

Meaning

Info

Array Name

The array to hold the results of the function.

nRelativeToForm </td>

Omitted

Return information about the mouse position relative to the container of the object over which the mouse is positioned.

1 (or any other value)

Return information about the mouse position relative to the containing form.

nFoundSomething

4

The mouse is positioned over an object and the array has been filled with the information.

0

The mouse is positioned over something that's not an object in the sense of this function and the array is unchanged.

The function doesn't handle grids properly. When you call AMouseObj() with the mouse over a grid column (either the header or the control in the grid) and omit the second parameter, both object references point to the column. Sounds like somebody can't decide how deep to drill here. The GridHitTest method can help you work around this one.

You need to release the array (or at least null the first two elements) before you can release the form. Otherwise, the references in the array prevent the form from being destroyed.

Like SYS(1270), this function tells you about the mouse position without requiring a click. Because it's available at design-time as well as runtime (as is SYS(1270)), we suspect it'll see a lot of use in builders. ### Example ```foxpro * Find out if we're over a particular object IF AMouseObj(aWhereAreWe) = 4 * Got something IF aWhereAreWe[1] = oSomeObject && note that we can now && compare objects directly * Do something ELSE * Do something different ENDIF ENDIF ``` ### See Also [ASelObj()](/section4/s4g289.html), [GridHitTest](/section4/s4g787.html), [Sys(1270)](/section4/s4g576.html)