Capture a window when the screen is off

I use Native GDI + to capture a window "on top of the screen." Does not work when the screen is off (generates a black image). How can i fix this? (I am using .Net 4.5)

public static Image CaptureWindow(IntPtr handle) { IntPtr hdcSrc = User32.GetWindowDC(handle); RECT windowRect = new RECT(); User32.GetWindowRect(handle, ref windowRect); int width = windowRect.right - windowRect.left; int height = windowRect.bottom - windowRect.top; IntPtr hdcDest = Gdi32.CreateCompatibleDC(hdcSrc); IntPtr hBitmap = Gdi32.CreateCompatibleBitmap(hdcSrc, width, height); IntPtr hOld = Gdi32.SelectObject(hdcDest, hBitmap); Gdi32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY); Gdi32.SelectObject(hdcDest, hOld); Gdi32.DeleteDC(hdcDest); User32.ReleaseDC(handle, hdcSrc); Image image = Image.FromHbitmap(hBitmap); Gdi32.DeleteObject(hBitmap); return image; } 
+5
source share
1 answer

As far as I know, the graphics driver stops creating an image when there is no one to get it in order to save energy. This may be the reason that you cannot capture the image when the screen is off. It makes no sense to use the power of the processor, GPU and bus to create an image when there is no one to get it.

0
source

Source: https://habr.com/ru/post/1241158/


All Articles