2

How to grab a screenshot of a DirectX window that is not in foreground and doesn't have focus. I want to monitor what happens with application in the background, but without switching to it.

The standard way with PrintWindow doesn't work. You can test that on Unity apps, for example.

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140
  • It is very common for real-time graphics applications to not render anything when the viewport is not visible. Your proposed solution will in general not work. – IInspectable Jun 07 '15 at 14:58
  • @IInspectable and if window is partially visible? Or located on virtual desktop? – anatoly techtonik Jun 07 '15 at 16:31
  • You could try to use the [DWM Thumbnail API](https://msdn.microsoft.com/en-us/library/windows/desktop/aa969541.aspx). This will not work, if the application is running on a virtual desktop; you'd have to implement a server application running on the same desktop. – IInspectable Jun 07 '15 at 17:50
  • PrintWindow works on normal windows because it asks the window to redraw itself. Generally speaking Direct3D applications don't render on demand like this, they constantly render frames as fast they can. That means they ignore requests to draw their windows, whether by PrintWindow, WM_PRINT or even WM_PAINT. You'll either have to hook the program so you can store the rendered window as its drawn, or copy it from wherever Windows might have stored it. In the case of a partially visible window DWM might have it, but only the visible part would be available from the screen DC. – Ross Ridge Jun 07 '15 at 17:55
  • @RossRidge, so basically PrintWindow asks "could you please render your window to my memory buffer?" and DirectX replies "no, I can't waste my time on that". Ok. How can I "hook the program" or copy rendered window content - where Windows stores it? – anatoly techtonik Jun 08 '15 at 06:19
  • It's not DirectX, it's the application itself, and it simply ignores it. It's possible however to create a Direct3D application that does work with PaintWindow (One of mine happens to, for example). Hooking the program is a pretty advanced topic, but it's how programs like Fraps work. See http://stackoverflow.com/questions/1962142/take-screenshot-of-directx-full-screen-application. You can either use DWM as IInspectable said, or `BltBlt` from the screen DC. The later option will only get you the visible portion and I have no idea if it would work with virtual desktops. – Ross Ridge Jun 08 '15 at 09:48

0 Answers0