ObjectFromPoint Method (Desktop Object)

Applies to TestComplete 14.72, last modified on April 22, 2021

Description

The ObjectFromPoint method lets you obtain the onscreen object (a window, popup window or a non-handled object) that contains the pixel specified by the X and Y coordinates relative to the screen.

Declaration

TestObj.ObjectFromPoint(XYFindTransparent)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
X [in]    Required    Integer    
Y [in]    Required    Integer    
FindTransparent [in]    Optional    Boolean Default value: False   
Result An onscreen object

Applies To

The method is applied to the following object:

View Mode

To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.

Parameters

The method has the following parameters:

X

The horizontal coordinate (relative to the screen) of the desired pixel.

Y

The vertical coordinate (relative to the screen) of the desired pixel.

FindTransparent

Specifies whether to retrieve non-windowed controls. A non-windowed control is a control that cannot receive the focus, cannot be the parent of other controls, and does not have its own window. For example, TLabel and TShape are non-windowed controls.

The default value is False, non-windowed controls are not obtained and their parent onscreen object is returned instead.

Result Value

The onscreen object to which the specified pixel belongs.

Remarks

You can use the WindowToScreen method of an onscreen object to convert client-area coordinates to screen coordinates.

Example

The following code snippet obtains the object that is currently under the mouse pointer and posts its image and full name to the test log:

JavaScript, JScript

function Test ()
{
  var w = Sys.Desktop.ObjectFromPoint( Sys.Desktop.MouseX, Sys.Desktop.MouseY );
  Log.Picture( w.Picture(), "Object under the mouse pointer", w.FullName );
}

Python

def Test():
  w = Sys.Desktop.ObjectFromPoint( Sys.Desktop.MouseX, Sys.Desktop.MouseY )
  Log.Picture( w.Picture(), "Object under the mouse pointer", w.FullName )

VBScript

Sub Test
  Dim w
  Set w = Sys.Desktop.ObjectFromPoint( Sys.Desktop.MouseX, Sys.Desktop.MouseY )
  Call Log.Picture( w.Picture, "Object under the mouse pointer", w.FullName )
End Sub

DelphiScript

procedure Test;
var w : OleVariant;
begin
  w := Sys.Desktop.ObjectFromPoint( Sys.Desktop.MouseX, Sys.Desktop.MouseY );
  Log.Picture( w.Picture, 'Object under the mouse pointer', w.FullName );
end;

C++Script, C#Script

function Test ()
{
  var w = Sys["Desktop"]["ObjectFromPoint"]( Sys["Desktop"]["MouseX"], Sys["Desktop"]["MouseY"] );
  Log["Picture"]( w["Picture"](), "Object under the mouse pointer", w["FullName"] );
}

See Also

ObjectFromPoint Method
WindowToScreen Method

Highlight search results