We help IT Professionals succeed at work.

How to discover the screen coordinates of "another"/external form.

JAMES asked
Medium Priority
Last Modified: 2010-04-16

I am doing some "ghost" controlling of external applications from my app. but these rely on exact screen locations for the button clicks.

How can I find out the screen coordinates of another window that is not attached to my application.  I can retrieve the handle but how do I then use that to find the x,y for the top left and bottom right (for example).  With this information I can then work out where to click.

Many thanks.

Watch Question

        public static extern int FindWindow(string lpClassName, string lpWindowName);
        public static extern int GetWindowRect(int hwnd, ref Rectangle lprect);

I assume youve used FindWindow allready to get the handle of the window you want to 'remote control'
Getwindowrect will give us the rectangle of that screens position if called as follows:

Rectangle TargetWindow = new Rectangle();
int hwnd = FindWindow("CabinetWClass", "My Computer");
GetWindowRect(hwnd, ref TargetWindow) ;

in this case ive just got a handle to the my computer window, which is of class 'CabintWClass'.
If you need to find out the class of a window, use Spy++.

Any more questions?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Sorry for the delay - that's perfect.

Thanks very much.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.