views:

1059

answers:

7

This boggles me. DirectX bypasses everything and talks directly to the device driver, thus GDI and other usual methods won't work - unless Aero is disabled (or unavailable), all that appears is a black rectangle at the top left of the screen. I have tried what other have suggested on several forums, using DirectX to get the back buffer and save it, but I get the same result:

device->GetFrontBufferData(0, surface); D3DXSaveSurfaceToFile("fileName", D3DXIFF_BMP, surface, NULL, NULL);

Is there any way to get a screenshot of another full-screen DirectX application when Aero is enabled?

A: 

I don't think you can. The feature is called hardware overlay and is also often used by DRM enabled video software and games. By disabling the overlay feature it will however be possible to use screen capture. Aero uses DirectX which in turn uses the overlay feature so that is the answer to why it works with Aero disabled.

Christian Vik
It's not true. Some utilities can do such things. E.g. FRAPS http://www.fraps.com/
ThinkJet
Fraps hooks the directX system calls to inject its own directx commands to the remote directx device, as Gregory Pakosz suggested.
Alan
+2  A: 

There definitly is a way, and Fraps is a good example.

Alexander Taran
how does it answer the "how?"?
Gregory Pakosz
+3  A: 

Have a look at Detours.

Using Detours, you can instrument calls like Direct3DCreate9, IDirect3D9::CreateDevice and IDirect3D9::Present in which you perform the operations necessary to setup and then do a frame capture.

Gregory Pakosz
there is no reason for a downvote, this is really how it's done
Gregory Pakosz
+1  A: 

There is an open source program like fraps: taksi but looks outdated

jlru
+1  A: 

This is a snippet of the code I used as test just now, it seems to work.

width and height are the size of the SCREEN in windowed mode not the windows. So for me they are set to 1280 x 1024 and not the window I'm rendering to's size.

You'd need to replace mEngine->getDevice() with some way of getting your IDirect3DDevice9 too. I just inserted this code into a random d3d app I had to make it easier to test. But I can confirm that it captures both the output from that app AND another d3d app running at the same time.

Oh I've assumed this is D3D9 as you didn't say, I'm not sure about d3d10 or 11

IDirect3DSurface9* surface;
mEngine->getDevice()->CreateOffscreenPlainSurface(width, height, D3DFMT_A8R8G8B8,     D3DPOOL_SCRATCH, &surface, NULL);
mEngine->getDevice()->GetFrontBufferData(0, surface);
D3DXSaveSurfaceToFile("c:\\tmp\\output.jpg", D3DXIFF_JPG, surface, NULL, NULL);
surface->Release();
John Burton
I should say that I just got a black rectange too unless the width, height were correctly set to the full screen size, and it seems necessary to use that exact D3DFMT as well for your buffer format, at least I couldn't get it to work with a different format.
John Burton
A: 

Here is some discussion of how Fraps works. It is not simple.

http://www.woodmann.com/forum/archive/index.php/t-11023.html

Any trick that tries to read the front buffer from a different DirectX device, I suspect may only occasionally work due to luck of uninitialized memory.

Alan
+1  A: 

Here is a C# example of hooking IDirect3DDevice9 objects via DLL injection and function hooking using EasyHook (like Microsoft Detours). This is similar to how FRAPS works.

This allows you to capture the screen in windowed / fullscreen mode and uses the back buffer which is much faster than trying to retrieve data from the front buffer.

A small C++ helper DLL is used to determine the methods of the IDirect3DDevice9 object to hook at runtime.

Justin S.