How to get ElementFromPoint?

DangDKhanh-2637 941 Reputation points


I'm using the following code to get the element:

automation->ElementFromPoint(pt, &element)

however the problem is that I'm using camtasia for full screen recording, then the result element always returns camtasia window...

User's image

Is there a way to get the element from point in a certain application?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,473 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,593 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 41,911 Reputation points

    Assuming you are using ATL. Following snippet assumes pt contains the screen coordinates of the mouse cursor and pAuto contains an IUIAutomation interace pointer.

    CComPtr<IUIAutomationElement> pElement;
    CComPtr<IAccessible> pAcc;
    CComVariant vChild;
    HRESULT hr;
    hr = AccessibleObjectFromPoint(pt, &pAcc, &vChild);
    if (SUCCEEDED(hr))
        ATLASSERT(V_VT(&vChild) == VT_I4);
        hr = pAuto->ElementFromIAccessible(pAcc, V_I4(&vChild), &pElement);
        if (SUCCEEDED(hr) && pElement)
            // Insert code
    1 person found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    Comments have been turned off. Learn more