How to get ElementFromPoint?

D.D.K-2637 966 Reputation points
2023-05-04T04:16:06.09+00:00

Hi,

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 development | Windows API - Win32
Developer technologies | C++
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 49,536 Reputation points
    2023-05-12T08:19:16.5233333+00:00

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.