Reputation: 45
I am searching for a way to get the screen coordinate bounds of any arbitrary window that may be displayed on the desktop at any time on a Windows machine. For instance, say you have a pdf document open in adobe on the desktop, I'd like to be able to get the coordinates/bounds of that arbitrary window with some written program, which language is used is not important.
My specific question: Is the above possible?
What I've done so far is simply get the screen position of the mouse in Java using the PointerInfo class, specifically the getPointerInfo() method. (API here: http://docs.oracle.com/javase/6/docs/api/java/awt/PointerInfo.html). Again, all I've done is find out where the mouse is in screen coordinates, this is not directly related to my problem, but I thought it was a good place to start.
I'm not looking for someone to give me a code snippet of how this is done, simply acknowledgement that it can be done and perhaps a link to an API or class documentation to help out. Again, I'm not looking for a solution in any particular language.
Thank you for your time, -Kevin
EDIT: I've posted this in c# as it seems this may be the best language for this problem.
Upvotes: 2
Views: 1292
Reputation: 61993
Yes, of course it is possible. (And under windows the best language to use for this job is C#.)
There may be some way to do that by using only dotnet objects and invoking only dotnet functions, but I do not know of any such method.
The way that I know involves pinvoke, which is the mechanism through which managed code in dotnet can call unmanaged code in the native windows dlls.
Look at the WindowFromPoint
function:
http://www.pinvoke.net/default.aspx/user32.windowfrompoint
And once you have found the window, look at the GetWindowRect
function:
http://www.pinvoke.net/default.aspx/user32.getwindowrect
Upvotes: 2
Reputation: 168825
Is the end user motivated enough to help? If so it is easy.
Of course, there are some tweaks can be done. Offer expanded views of the boundary corners, offer ways to adjust each corner pixel by pixel.. If pursuing this strategy, you might start with this code which is designed to select a point on screen.
Upvotes: 0
Reputation: 19443
Look at this Javadoc for Window (Java AWT). It seems that it makes some attempt to do it, but it cannot guarantee.
Upvotes: 0