windowsscreenshotscreen-capturedwmscreen-recording

Screenshot of the specific window (HWND, HW accelerated)


I need to capture a snapshots/screenshots of the specific window (HWND) that is using HW acceleration and record them to a video stream.

While using BitBlt or PrintWindow I'm able to capture image data only if this window is not HW accelerated, else I'm getting a black texture.

Tried using User32.dll's undocumented DwmGetDxSharedSurface to get the DirectX surface handle. But it fails with an error:

ERROR_GRAPHICS_PRESENT_REDIRECTION_DISABLED - desktop windowing management subsystem is off

(Edit: Fails for certain applications, i.e. "calculator.exe")

Tried using Dwmapi.dll's undocumented functions DwmpDxUpdateWindowSharedSurface and DwmpDxGetWindowSharedSurface. I've managed to retrieve what looks like a valid DirectX surface handle. (it's d3dFormat, width and height information was valid) Dx's OpenSharedResource was not complaining and managed to create a valid ID3D11Texture2D. Problem is.. all bytes are zeros (getting a black texture). I might be doing something wrong here or.. undocumented DWM functionas does not work anymore on Windows 10...

Edit: I'm able to get image data for some applications like Windows explorer, Paint, etc, but for some like i.e. Slack i get all zeros/black image.

Edit: When capturing i.e. VLC, I get this: enter image description here

Question: Is there any other way to capture image data of the HW accelerated window?

Note: I don't want to capture the entire desktop.


Solution

  • You can use PrintWindow with nFlags=2 Or use Magnification API (exclude windows) Or try to hack dwm.exe.