Functions and Directives

Function XbpFromPoint() Foundation

Returns the Xbase Part residing at a certain screen position.

XbpFromPoint( <aPt>, [<lInclAll>] ) --> <oXbp> | NIL
<aPt> is an array of two elements which define the screen position of the Xbase Part. The position is specified relative to the coordinate system of the desktop object.
<lInclAll> is a logical value which specifies whether hidden or invisible Xbase Parts are returned by function XbpFromPoint(). The parameter defaults to .F. (false) meaning that hidden and invisible objects are ignored by this function.

The return value of XbpFromPoint() is the Xbase Part residing on the screen position specified. If no Xbase Part is found, the function returns NIL.


The function XbpFromPoint() returns the Xbase Part whose bounding rectangle encompasses a certain screen position. The position must be specified relative to the desktop. See the function AppDesktop() for further information on how to obtain the global desktop object. Also, consult the method XbpWindow:mapPoint() to learn more on how to convert a screen coordinate to a child-local coordinate and vice versa.

By default, XbpFromPoint() only respects the objects which are visible on the screen. Consequently, an Xbase Part that is marked invisible using the method XbpWindow:hide() is not returned by XbpFromPoint(). To change this behaviour, the value .T. (true) must be assigned to the <lInclAll> parameter.

XbpFromPoint() is often used in conjunction with GetPointerPos() to determine the object over which the mouse pointer resides.

Function XbpFromPoint() can only be used in GUI and Hybrid Mode applications (linker switch /PM:PM or GUI=yes in the project file).

// The example shows the usage of XbpFromPoint() to determine 
// whether the mouse pointer currently resides over an Xbase 
// Part. 
#include "" 
#include "" 


 LOCAL oCrt 
 LOCAL nEvent 
 LOCAL mp1 := NIL, mp2 := NIL 
 LOCAL oXbp := NIL 

   SetMouse( .T. ) 
   SetColor( "N/W+" ) 

   // Make the console window respect standard 
   // Windows key combinations such as ALT+F4. 
   // Ensure that closing the console terminates 
   // the example. 
   oCrt := SetAppWindow() 
   oCrt:UseShortCuts := .T. 
   oCrt:Close := {|| PostAppEvent(xbeP_Quit)} 

   // Populate the console window in order to 
   // get objects to work with. Activating the 
   // push button created initiates a search 
   // for the current object using XbpFromPoint() 
   oPb := XbpPushButton():New( oCrt ) 
   oPb:Caption   := "Press SPACE..." 
   oPb:Activate  := {|| SearchXbp(GetPointerPos())} 
   oPb:Create( ,, {50,50}, {250,50} ) 

   oXbp := XbpStatic():New( oCrt ) 
   oXbp:Caption  := "Press the SPACE bar while the push button "   +; 
                    "has the input focus. This returns the Xbase " +; 
                    "Part currently under the mouse pointer. The " +; 
                    "Xbase Part is located using XbpFromPoint()." 
   oXbp:Create( ,, {50,150}, {260,150} ) 

   oXbp := XbpListBox():New( oCrt ) 
   oXbp:Create( ,, {350,50}, {220,200} ) 

   SetAppFocus( oPb ) 

   nEvent := xbeP_None 
   DO WHILE nEvent != xbeP_Quit 
      nEvent := AppEvent( @mp1, @mp2, @oXbp ) 
      oXbp:HandleEvent( nEvent, mp1, mp2 ) 



// Check whether an Xbase Part is located at 
// the screen position passed in "aPos" 
PROCEDURE SearchXbp( aPos ) 
 LOCAL oXbp 

   oXbp := XbpFromPoint( aPos ) 
   IF oXbp == NIL 

   MsgBox( "The pointer resides over an object of class " +; 
           Var2Char(oXbp:ClassName()) ) 

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.