views:

186

answers:

2

Hi, does anyone know if you can get the coordinates of a window using the .NET framework or via pinvoking?

I would have the processID or mainwindowhandle.

+1  A: 

In Windows Forms API, form.Top and form.Left should do.

If all you have is the process Id, you can iterate through the process's widows using EnumWindowsProc windows API method. once you get the window's handle which you want, you can query for its size and position.

Frederick
i dont have access to the application though..
Grant
Which application? Please mention your specific scenario in the question.
Frederick
Is your question this: how can I get the position of the main window of an application if I have its process ID?
Frederick
I want to center a form over an application that i did not produce. so i need to somehow gets its coordinates to center it correctly.
Grant
+1  A: 

HI, you can use System.Windows.Forms.Control cr= System.Windows.Forms.Control.FromHandle(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); now u can get location of that control.

Firoz