c# - Identifier for a Windows GUI element (AutomationElement HashCode and RuntimeID) -
i looking way identify instances of gui element (for example "copy" entry in context menu of windows explorer).
i tried both .gethashcode , .getruntimeid method on automationelement, both change each time open context menu.
what difference/purpose between runtimeid , hashcode anyway?
any ideas how identfy gui element without comparing label/name string?
there various ways, under automationelement class able inspect "current" element , use combination of ways determine element. following example taken solution see here
using system.window.automation; private automationelement element; system.drawing.point mouse = system.windows.forms.cursor.position; this.element = automationelement.frompoint(new system.windows.point(mouse.x, mouse.y));
from here able access element.current , extract things such name, processid.
although may have figured out, following code should class name of current ui item, not part of automationelement class , win32 hook.
[dllimport("user32.dll")] public static extern int getclassname(intptr hwnd, stringbuilder lpclassname, int nmaxcount); private string getclassname(intptr hwnd) { stringbuilder sb = new stringbuilder(256); this.getclassname(hwnd, sb, 256); return sb.tostring(); }
hope helps, if started ;)
rh
Comments
Post a Comment