1

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.

Gediminas
  • 1,830
  • 3
  • 27
  • 47
  • Which technology is the application using? Does it only fail on UWP apps? Does the DWM thumbnail API work or is it also blank? – Anders Apr 26 '19 at 10:26
  • @Anders I was testing with windows calculator.exe. DWM thumbnail is able to capture and show the duplicated "thumbnail" image in my window. But DwmGetDxSharedSurface (User32.dll) fails with the specified error. – Gediminas Apr 26 '19 at 10:35
  • Did you find the solution? I am having the same issue – user1428926 Apr 18 '20 at 23:35
  • @user1428926 I did not, if you will, please let me know. – Gediminas Apr 19 '20 at 16:56
  • @Gediminas do you still have the code for DwmGetDxSharedSurface() or DwmpDxGetWindowSharedSurface() – trickymind Jul 28 '21 at 07:47
  • @trickymind, take a look: https://pastebin.com/i9ibFX99 It's just some old experimental trash code. Hope you'll find something useful. – Gediminas Jul 28 '21 at 15:51
  • @Gediminas Thank you so much for helping, i have been surfing internet for a week to get a sample code of this Dwm Function – trickymind Jul 29 '21 at 11:09
  • @trickymind, np, additionally, try and take a look: https://spazzarama.com/2009/02/12/screen-capture-with-vista-dwm/ – Gediminas Jul 31 '21 at 09:34

1 Answers1

2

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

malcev
  • 64
  • 1
  • 8
  • Thank you. I was not aware of the "PW_RENDERFULLCONTENT" flag (nFlags=2). There is no information about it in the "PrintWindow" documentation.. – Gediminas Sep 15 '20 at 13:38