views:

1787

answers:

4

How can I get and set the position of another application using c#? For example, I would like to get the top left hand coordinates of Notepad (lets say it's floating somewhere at 100,400) and the position this window at 0,0.

What's the easiest way to achieve this?

+2  A: 

Try using FindWindow (signature) to get the HWND of the target window. Then you can use SetWindowPos (signature) to move it.

David
+1  A: 

You will need to use som P/Invoke interop to achieve this. The basic idea would be to find the window first (for instance, using the EnumWindows function), and then getting the window position with GetWindowRect.

driis
+2  A: 

I actually wrote an open source DLL just for this sort of thing you can check out. Here

This will allow you to find, enumerate, resize, reposition, or do whatever you want to other application windows and their controls. There is also added functionality to read and write the values/text of the windows/controls and do click events on them. It was basically written to do screen scraping with - but all the source code is included so everything you want to do with the windows is included there.

DataDink
A: 

The link of dll doesnt work. James have you got it?

koc