Roger Gajraj
Roger Gajraj

Reputation: 533

get any UI element's on screen position for any application in windows

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

Answers (1)

JPW
JPW

Reputation: 1211

To get the position of a control in an external application you basically have to go through the following steps:

  • Call EnumWindows which enumerated all top level windows
  • For the top level window you are interested in call EnumChildWindows
  • Call GetWindowRect for the child window (control) whose position you want to retrieve

The 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

Related Questions