Function SetMouse() Foundation

Turns mouse on or off.

SetMouse( [<lOnOff>] ) --> lMouseOn
<lOnOff> is a logical expression specifying whether the mouse is turned on. When it is .T. (true), the mouse is turned on. When it is .F. (false), the mouse is turned off.

The return value of SetMouse() is a logical value which identifies the condition of the mouse prior to this call to SetMouse(). If it is .T. (true) the mouse was turned on, .F. (false) means it was turned off.


The environment function SetMouse() turns on or off the recognition of mouse events. If a program is running in character mode, the mouse pointer is also turned on or off. When the program is running in graphic mode, either as a VIO application in a window or as a Presentation Manager application, the mouse pointer cannot be turned off. A call to SetMouse(.F.) simply causes the function AppEvent() to stop registering mouse events.

Mouse events are coded as numeric values. To easily process them within a program, #define constants are defined for all events in the #include file The most important constants are presented in the following table:

Symbolic constants for mouse events
Constant Event
xbeM_LbDown Left mouse button pressed
xbeM_RbDown Right mouse button pressed
xbeM_LbUp Left mouse button released
xbeM_RbUp Right mouse button released
xbeM_Motion Mouse is moved
xbeM_LbClick Click of left mouse button
xbeM_RbClick Click of right mouse button
xbeM_LbDblClick Double click of left mouse button
xbeM_RbDblClick Double click of right mouse button

By default the mouse is turned off. To be sure mouse events are processed in a program, the call SetMouse(.T.) must occur at the beginning of a program.

Coordinates: The coordinates of the mouse pointer are found in the first parameter after the call to the function AppEvent(). It is an array with two elements containing numeric values for the position of the mouse pointer. By default the coordinates for VIO (text) mode are returned. The current window (XbpCrt object) has two settings for the mouse coordinates: text mode and graphic mode. Switching between the two modes is done as follows:

                                  // graphic x,y coordinates 
SetAppWindow():mouseMode := XBPCRT_MOUSEMODE_PM 
                                  // text coordinates nRow and nCol 
SetAppWindow():mouseMode := XBPCRT_MOUSEMODE_VIO 

Constants for the mode in which mouse coordinates are reported are defined in the include file

Enabling mouse support via SetMouse(.T.) switches off the so-called "Quick Edit" mode of the Windows command prompt. In quick edit mode, mouse clicks and similar events are consumed by Windows for providing editing and similar functionality, and are no longer reported to the Xbase++ application. This only concerns character mode (VIO) applications running in a commandline/console.

// The example shows a simple test program for the mouse and 
// processing mouse events. When the left button is pressed, 
// output occurs on the screen at the position of the mouse 
// pointer. The right mouse button terminates the example program. 

#include "" 

   LOCAL nMouseRow, nMouseCol, nEvent, mp1 
   LOCAL nColor := 0 


   SetMouse( .T. )                  // turns mouse on 

   SET COLOR TO "W+/N,R+/N,B+/N,G+/N,BG+/N" 

   DO WHILE .T. 

      nEvent    := AppEvent( @mp1 ) 

      IF nEvent == xbeM_LbDown      // left mouse button pressed 
         nColor++                   // change color for the display 
         IF nColor > 4 
            nColor := 0 
         ColorSelect( nColor ) 
         nMouseRow := mp1[1] 
         nMouseCol := mp1[2] 
         @ nMouseRow, nMouseCol SAY  "<- you clicked here" 

      ELSEIF nEvent == xbeM_RbDown  // right mouse button pressed 



If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.