When I was researching for this article, I noticed some passing references to the Vista DWM (Desktop Window Manager) and the ability to use it to capture images of windows — DWM is the technology behind Windows Aero and its window switching features like Flip3D. I filed this away as something to look into at a later date.
Update: 2010-03-29: An example of hooking the Direct3D API directly in C#: http://spazzarama.com/2010/03/29/screen-capture-with-direct3d-api-hooks/
Well I finally got back to it and found this great article by Jeremiah Morrill, including an example project for capturing Direct3D/WPF windows using the DWM and streaming it to video. The main advantage of using this approach over my previous article is that the Direct3D/WPF window being captured does not need to be visible – it can be behind another window, or even partially off screen – but not minimized.
The example project allows you to save a video of the window to WMV or stream it over the network. Note: although the video is not of the original resolution/quality, the actual bitmap captured is – and you can grab this instead if you need a full quality image/video.
My initial tests showed that this technique does not work for full-screen Direct3D applications. I would be interested to see if anyone else had any luck.
Update: April 11th 2009
I have now prepared a cut down C# sample project for capturing the contents of a WPF / Direct3D window to a Bitmap based on Jeremiah’s code.