0

As discussed in a previous post, I'm making an equivalent of Inspect.exe. To do this, I'm using IAccIdentity to obtain a "unique" ID of each control.

However, it turns out these IDs are NOT unique?

Proof of non-uniqueness

In this case, I could use accName to distinguish the elements, but I fear that this won't guarantee anything... Is there any method of obtaining a guaranteed unique reference to an element which is object instance independent?

Note: I concatenated the role in there too, to try to make it more unique, but failed.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
Sancarn
  • 2,575
  • 20
  • 45
  • `IAccIdentity` provides a unique identifier for `an accessible element`. If you want to obtain a "unique" ID of each control. I suggest you could try to use [GetDlgCtrlID](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdlgctrlid) – Jeaninez - MSFT Aug 04 '23 at 03:05
  • If you're writing an inspect equivalent, you should use UI Automation instead of MSAA, each element has a unique per desktop id IUIAutomationElement::GetRuntimeId: https://learn.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getruntimeid – Simon Mourier Aug 04 '23 at 05:13
  • @SimonMourier From the docs: "`AutomationIdProperty` does not guarantee a unique identity throughout the tree" - so from what I gather this won't be helpful either? – Sancarn Aug 04 '23 at 08:57
  • @Jeaninez-MSFT These 2 controls have the same `hwnd`... So i'd imagine they'd have the same `CtrlID` too? – Sancarn Aug 04 '23 at 08:59
  • 1
    I talked about RuntimeId, not AutomationId, they are different things. – Simon Mourier Aug 04 '23 at 10:36
  • As far as I'm concerned, it is impossible to have the same HWND in the same desktop. In my opinion, If the hwnd is the same, the CtrlID is the same. – Jeaninez - MSFT Aug 07 '23 at 02:30

0 Answers0