MouseMove

The MouseMove event has different arguments for different objects:

Object

See

RichTextEdit control

Syntax 1

Window

Syntax 2


Syntax 1: For RichTextEdit controls

Description

Occurs when the mouse has moved within the RichTextEdit control.

Event ID

Event ID

Objects

pbm_renmousemove

RichTextEdit


Arguments

None

Return Values

Long.

Return code choices (specify in a RETURN statement):

0 -- Continue processing

See also

Clicked

MouseDown

MouseUp

Syntax 2: For windows

Description

Occurs when the pointer is moved within the window.

Event ID

Event ID

Objects

pbm_mousemove

Window


Arguments

Argument

Description

flags

UnsignedLong by value (the modifier keys and mouse buttons that are pressed).

Values are:

  • 1 -- Left mouse button

  • 2 -- Right mouse button

  • 4 -- Shift key

  • 8 -- Ctrl key

  • 16 -- Middle mouse button

Flags is the sum of all the buttons and keys that are pressed.

xpos

Integer by value (the distance of the pointer from the left edge of the window's workspace in pixels).

ypos

Integer by value (the distance of the pointer from the top of the window's workspace in pixels).


Return Values

Long.

Return code choices (specify in a RETURN statement):

0 -- Continue processing

Usage

Because flags is a sum of button and key numbers, you can find out what keys are pressed by subtracting the largest values one by one and checking the value that remains. For example:

  • If flags is 5, the Shift key (4) and the left mouse button (1) are pressed.

  • If flags is 14, the Ctrl key (8), the Shift key (4), and the right mouse button (2) are pressed.

This code handles all the buttons and keys (the local boolean variables are initialized to false by default):

boolean lb_left_button, lb_right_button
boolean lb_middle_button, lb_Shift_key, lb_control_key
integer li_flags
 
li_flags = flags 
IF li_flags > 15 THEN
   // Middle button is pressed
   lb_middle_button = TRUE
   li_flags = li_flags - 16
END IF
 
IF li_flags > 7 THEN
   // Control key is pressed
   lb_control_key = TRUE
   li_flags = li_flags - 8
END IF
 
IF li_flags > 3 THEN
   // Shift key is pressed
   lb_Shift_key = TRUE
   li_flags = li_flags - 4
END IF
 
IF li_flags > 1 THEN
   // Right button is pressed
   lb_right_button = TRUE
   li_flags = li_flags - 2
END IF
 
IF li_flags = 1 THEN lb_left_button = TRUE

Most controls in a window do not capture MouseMove events -- the MouseMove event is not mapped by default. If you want the window's MouseMove event to be triggered when the mouse moves over a control, you must map a user-defined event to the pbm_mousemove event for the control. The following code in the control's user-defined MouseMove event triggers the window's MouseMove event:

Parent.EVENT MouseMove(0, Parent.PointerX(), Parent.PointerY())

Examples

This code in the MouseMove event causes a meter OLE custom control to rise and fall continually as the mouse pointer is moved up and down in the window workspace:

This.uf_setmonitor(ypos, ole_verticalmeter, &
   This.WorkspaceHeight() )

Uf_setmonitor is a window function that scales the pixels to the range of the gauge. It accepts three arguments: the vertical position of the mouse pointer, an OLECustomControl reference, and the maximum range of the mouse pointer for scaling purposes:

double ld_gaugemax, ld_gaugemin
double ld_gaugerange, ld_value
 
// Ranges for monitor-type control
ld_gaugemax = ocxitem.Object.MaxValue
ld_gaugemin = ocxitem.Object.MinValue
ld_gaugerange = ld_gaugemax - ld_gaugemin
 
// Horizontal position of mouse within window
ld_value = data * ld_gaugerange / range + ld_gaugemin
 
// Set gauge
ocxitem.Object.Value = Round(ld_value, 0)
 
RETURN 1

The OLE custom control also has a MouseMove event. This code in that event keeps the gauge responding when the pointer is over the gauge. (You need to pass values for the arguments that are usually handled by the system; the mouse position values are specified in relation to the parent window.) For example:

Parent.EVENT MouseMove(0, Parent.PointerX(), &
Parent.PointerY())

See also

Clicked

MouseDown

MouseUp