Pedro Pedro - 2 months ago 41
C# Question

WinAPI - Get all Control-Handles of a Window-Handle

i've tried to work a little bit with UI-Automation,
at the moment i try to get all Handles of a process (Handles of all Windows and their Controls), but i've problems to get some control handles, where the RuntimeId (Read by UISpy) is like "42 592195 2 26" instead of "42 592195".
(Where 592195 is the handle of the window and the other two numbers after that should somehow get me the handle of the specific Control)

Anyone know how to get these handles to get the control-rectangle for example?


You can use FindAll method to find all elements relative to given element based on some condition. Then you can get properties from those elements.

For example:

var notepad = System.Diagnostics.Process.GetProcessesByName("notepad").FirstOrDefault();
if (notepad != null)
    var root = AutomationElement.FromHandle(notepad.MainWindowHandle);
    var elements = root.FindAll(TreeScope.Subtree, Condition.TrueCondition)
    //elements.Select(x => x.Current.ControlType);
    //elements.Select(x => x.Current.NativeWindowHandle);
    //elements.Select(x => x.Current.BoundingRectangle);