[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-03-31
2
Medium Priority
?
279 Views
Last Modified: 2010-04-16
Hi,

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.

James.
0
Comment
Question by:JAMES
2 Comments
 
LVL 4

Accepted Solution

by:
SmithJW earned 2000 total points
ID: 16342331
       [DllImport("user32.dll")]
        public static extern int FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll")]
        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?
0
 

Author Comment

by:JAMES
ID: 16369657
Sorry for the delay - that's perfect.

Thanks very much.

James.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question