Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if a window is using hardware-accelerated graphic context

I'm using BitBlt winapi function to take a screenshot of a given window, even if the window is partially overlapped.
I have everything working fine already, except that, on Windows 10, for some windows (like the Edge browser) the screenshot turns out completely black.

A number of other questions concur on attributing this problem to the use of a hardware-accelerated graphics context on those windows.

  • BitBlt screen capture not working on Windows 10
  • Screenshot with BitBlt results in black image on Windows 10
  • Screenshot captured using BitBlt in C# results a black image on Windows 10
  • BitBlt not capturing windows in Hardware accelerated mode
  • AutoHotkey-GDIp: Capture a screenshot from a hardware accelerated window

Apparently the GDI library is incompatible with that kind of graphics context so a different library has to be used.

My question is specifically about how to detect if a window is using a graphics context that's incompatible with the GDI library.

If I'm able to detect this, then I can choose which library to use for capturing the screenshot correctly (GDI, ActiveX or other).

Otherwise, the only way I could detect this is by scanning the screenshot pixel by pixel to check that's completely black. Then using a different capture method till I get some content on the screenshot.
But this sounds like an awful solution.

like image 808
Tim Avatar asked May 30 '19 23:05

Tim


1 Answers

I have everything working fine already, except that, on Windows 10, for some windows (like the Edge browser) the screenshot turns out completely black.

You can use DwmRegisterThumbnail to capture hidden/overlapped windows, in particular UWP (like Edge, Calc, etc...)

I use it on Windows 10 without problem (+ D3D to save the bitmap)

like image 57
Castorix Avatar answered Oct 21 '22 08:10

Castorix