Veréis quiero capturar con cierta frecuencia una ventana. Según he podido encontrar este sería el código que se usaría. Funcionar me funciona, el problema está en que cuando lleva varios minutos, la pantalla que está capturando empieza a verse mal. Alguna idea para mejorar esto y que la otra ventana se vea bien?
Código:
public static Bitmap GetWindow(IntPtr hWnd)
{
Bitmap bmp = null;
IntPtr hdc = GetDC(hWnd);
if ((int)hdc != 0)
{
IntPtr hdcMem = CreateCompatibleDC(hdc);
if ((int)hdcMem != 0)
{
IntPtr hbitmap = CreateCompatibleBitmap(hdc, GetSystemMetrics(0), GetSystemMetrics(1));
if ((int)hbitmap != 0)
{
SelectObject(hdcMem, hbitmap);
if (PrintWindow(hWnd, hdcMem, 1))
{
bmp = System.Drawing.Image.FromHbitmap(hbitmap);
}
}
DeleteObject(hbitmap);
}
DeleteObject(hdcMem);
}
ReleaseDC(hWnd, hdc);
return bmp;
}
Muchas gracias.