Search code examples
winapiuiaccessibilitymicrosoft-accessibility

MSAA - How to check if 2 automation elements refer to the same thing?


I am making an application which intends to behave like inspect.exe. I have a treeview of accessibility elements which are queried on demand as the user navigates through the elements. I want to implement the 'Watch Cursor' feature now.

I can obtain the currently hovered element using AccessibleObjectFromPoint. And I can call IAccessible::get_accParent until I reach the intersection point with my existing elements shown in the treeview. However, the object returned from this function is different to the object pointers returned from this property are different to the ones in my treeview representing the same UI element.

How do you go about comparing 2 elements and understanding whether they are equal?

Is there some UID that I can obtain from the IAccessible (or a similar interface) which can be used to uniquely identify elements?


Solution

  • This is what IAccIdentity::GetIdentityString is for.

    1. Use IUnknown::QueryInterface for IAccIdentity (IID: {7852B78D-1CFD-41C1-A615-9C0C85960B5F})
    2. On the returned object call IAccIdentity::GetIdentityString with dwIDChild param set to 0
    3. Do a memcmp on the returned buffers.

    additionally remember to call CoTaskMemFree after copying the identity string into memory.