Reputation: 533
is there a way in any programming language, perhaps using the Microsoft SDK, to get the on screen position of UI elements within a window of any application ? If so, could you please provide guidance with an example perhaps? Thank you, It's been paining me for days!
Please consider that it is an external application. So for example, if I opened MS word, my application should be able to get the screen location of the "Bold" button.
So far, I believe I will need to use hooks.
Upvotes: 1
Views: 3702
Reputation: 1211
To get the position of a control in an external application you basically have to go through the following steps:
EnumWindows
which enumerated all top level windowsEnumChildWindows
GetWindowRect
for the child window (control) whose position you want to retrieveThe details for this depend on what you are exactly trying to achieve.
Alternativly you could use the Windows Automation API (http://msdn.microsoft.com/en-us/library/dd561932(VS.85).aspx) with GetCurrentPorpertyValue(UIA_BoundingRectanglePropertyId, result)
.
I don't know if there are managed wrappers for this functions, but you could fallback to P/Invoke.
Have also a look into the UI Spy tool which ships with the Windows SDK (http://msdn.microsoft.com/en-us/library/ms727247.aspx).
Upvotes: 2