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.

MROW(), MCOL(), MWINDOW(), MDOWN()

These functions let you find out what’s going on with the mouse. MROW() and MCOL() provide the current mouse position, while MWINDOW() tells you which window the mouse is in. MDOWN() tells you whether a mouse button is down at the moment.

You can get just about all the same information using various events including MouseMove and MouseDown.

Usage

nYCoord = MROW( [ cWindow ] )
nXCoord = MCOL( [ cWindow ] )

Parameter

Value

Meaning

cWindow

Character

Return coordinates relative to the specified window.

Omitted

Return coordinates relative to the active window. If no user-defined window is active, return coordinates relative to the main Visual FoxPro window.

MROW() and MCOL() have interesting behavior. Their output is always relative to a particular window and is given in foxels. When a user-defined window is active, these functions are dynamic. You can watch them change in the Debugger. When no user-defined window is active, the Debugger values update only when you click somewhere. No doubt the difference is the presence of the MouseMove event of a form, which tracks the mouse position anyway.

When the mouse is positioned outside the specified window in either dimension, the function for that dimension returns –1. (For example, if the mouse is below the window, MROW() returns –1.)

When the Debugger is in its own frame, clicking into it evaluates these functions with respect to the position of the VFP frame. Kind of strange, but not terribly important since users aren’t likely to run your apps with the Debugger open.

Usage

cWindow = MWINDOW()
lIsThisWindow = MWINDOW( cWindow )

MWINDOW() does two different things. By itself, it returns the name of the window the mouse is currently over (which is the form whose MouseMove would be triggered at the moment if it contained any code). Pass it a window name and it tells you whether the mouse is over that window.

Usage

lButtonDown = MDOWN()

MDOWN() lets you know if either mouse button is currently pressed. It returns .T. as long as the button is down. MDOWN() has trouble keeping up when you’re not in a window.

We used to use all of these functions in attempts to make event-driven applications in FoxPro 2.x. We really don’t use them much in VFP because the enhanced event model provides these capabilities and much more, though we occasionally use MDOWN() to do manual drag-and-drop or something like the example.

Example

DO WHILE MDOWN()
   * increase a variable while the mouse button is down
   nCount = nCount+1
ENDDO

See Also

Click, MiddleClick, MouseDown, MouseMove, MouseUp, RightClick, WOnTop(), WOutput()