Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get window's position? [duplicate]

I'd like to know the way of getting process'es window position. I've been looking for that on the internet but with no results. Thanks :)

Process[] processes = Process.GetProcessesByName("notepad");
Process lol = processes[0];

IntPtr p = lol.MainWindowHandle;
like image 451
Patryk Avatar asked Mar 12 '12 14:03

Patryk


1 Answers

Try this:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);

[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);

public struct Rect {
   public int Left { get; set; }
   public int Top { get; set; }
   public int Right { get; set; }
   public int Bottom { get; set; }
}

Process[] processes = Process.GetProcessesByName("notepad");
Process lol = processes[0];
IntPtr ptr = lol.MainWindowHandle;
Rect NotepadRect = new Rect();
GetWindowRect(ptr, ref NotepadRect);
like image 170
ionden Avatar answered Sep 28 '22 04:09

ionden