Share via


IRawElementProviderFragmentRoot::ElementProviderFromPoint Method

Retrieves the element in this fragment that is at a specified point.

Syntax

HRESULT ElementProviderFromPoint(      
    double x,
    double y,
    IRawElementProviderFragment **pRetVal
);

Parameters

  • x
    [in] The horizontal screen coordinate.
  • y
    [in] The vertical screen coordinate.
  • pRetVal
    [out, retval] The address of a variable that receives a pointer to the IRawElementProviderFragment interface of the element at (x, y), or NULL if none exists. This parameter is passed uninitialized.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

The returned provider should correspond to the element that would receive mouse input at the specified point.

If the point is on this element but not on any child element, either NULL or the provider of the fragment root is returned. If the point is on an element in another framework that is hosted by this fragment, the method returns the element that hosts that fragment (as indicated by IRawElementProviderFragment::GetEmbeddedFragmentRoots).

Example

The following example shows an implementation for a list box hosted in an HWND whose handle is m_controlHwnd. IndexFromY retrieves the index of the list item at the cursor position, and GetItemByIndex retrieves the UI Automation provider for that item.

HRESULT STDMETHODCALLTYPE ListProvider::ElementProviderFromPoint(double x, double y, IRawElementProviderFragment** pRetVal)
{
    if (pRetVal == NULL) 
    {
        return E_INVALIDARG;
    }
    POINT pt;
    pt.x = (LONG)x;
    pt.y = (LONG)y;
    ScreenToClient(m_controlHwnd, &pt);
    int itemIndex = this->m_pControl->IndexFromY(m_controlHwnd, pt.y);
    ListItemProvider* pItem = GetItemByIndex(itemIndex);  
    if (pItem != NULL)
    {
        *pRetVal = (IRawElementProviderFragment*)pItem;
        pItem->AddRef();
    }
    else 
    {
        pRetVal = (IRawElementProviderFragment*)this;
        pItem->AddRef();
    }

    return S_OK;
}            

See Also

IRawElementProviderFragmentRoot