Why am I getting height and width 0 using below:
static void Main(string[] args) { Process notePad = new Process(); notePad.StartInfo.FileName = "notepad.exe"; notePad.Start(); IntPtr handle = notePad.Handle; RECT windowRect = new RECT(); GetWindowRect(handle, ref windowRect); int width = windowRect.Right - windowRect.Left; int height = windowRect.Bottom - windowRect.Top; Console.WriteLine("Height: " + height + ", Width: " + width); Console.ReadLine(); }
Here is my definition of GetWindowRect:
[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
This is my definition for RECT:
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left;
Thanks to everyone for any help.
source share