¿Por qué obtengo un Altura y Ancho de 0 con el siguiente:¿Por qué obtengo una altura y un ancho de 0?
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();
}
Aquí es mi definición de GetWindowRect:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
Esta es mi definición de RECT:
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
Gracias a todos por cualquier ayuda.
¿cómo definió RECT? –
Sospecho que es una carrera: intente agregar unos segundos para dormir después de la línea de Inicio() para que el bloc de notas se ponga en funcionamiento. No estoy seguro de cómo esperar esto programáticamente. – Rup
Además, ¿cuál es el valor devuelto por GetWindowRect? –