Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to get all ui elements of a window?

I want to get a list of all UI elements of a window, In a way I can recreate them on another PC? Currently I am focused on windows but a multi-platform answer will be greatly appreciated. Thanks! (What I mean below)

enter image description here

like image 593
Wazzaps Avatar asked Oct 01 '22 17:10

Wazzaps


1 Answers

There are a couple of ways to go.

Option 1: If the window is a traditional one where the UI elements are child windows (rather than windowless controls), then you can use GetWindow or EnumChildWindows to iterate through the UI elements in a given window. You then would have to examine attributes of those windows, like the window procedure, window styles, and window text, to build a list like you're suggesting. You could probably make this work for all the standard controls. The problem is making it general enough to handle everything. Lots of applications have custom control types that your code wouldn't be prepared to recognize, or it might lay them out in ways that aren't obvious. You also won't be able to deal with windows that use windowless controls.

Options 2: You can use UI Automation to walk the tree of UI controls. This is how accessibility technologies like screen readers interact with applications.

like image 190
Adrian McCarthy Avatar answered Oct 06 '22 00:10

Adrian McCarthy