Reputation: 539
i'm using c# .net 4.5;
my question is how could i get the cmd location.
for example to get my own form location i use this.Location
and i'm getting the x and the y.
how could i do it for an application which is running but has nothing to do with my own app? i know it's possible because windows 8 use something like that. :)
thanks for helping...
Upvotes: 0
Views: 120
Reputation: 114
Your question at first glance seems you want the location of the application exe and not the position of the window. If you want the position of the window you need to use API.
[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int left;
public int top;
public int right;
public int bottom;
}
[DllImport("user32.dll")]
public static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect
And then use it like so:
var proc = Process.GetProcessesByName(proccessName)[0];
Rect rect = new Rect();
GetWindowRect(proc.MainWindowHandle, ref rect);
Hope it helps
For more information look at MSDN and pInvoke
Upvotes: 3