Question

I've got an application that is very graphics intensive and built on DirectX and Windows Forms. It has an automation and replay framework around which is built an automated testing system. Unfortunately, when the tests run unattended during a nightly build, the display is inactive or tied up with the screensaver, and our IT security policies don't allow us to disable that.

So my question: is there a way to do a "screen" capture of an application that is running without the display? I'd like to ensure that the graphics card is engaged so that my rendering pipeline is the same, but the testing framework shouldn't need to care about the state of the display.

Any help wildly appreciated!

Was it helpful?

Solution

Since you're mentioned rendering pipeline, so I'm assuming you're using Direct3d, if so, you can save the backbuffer of the frame. I did that when I was still using VB.Net + MDX

Dim tempSurface As Direct3D.Surface
tempSurface = device.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)
Direct3D.SurfaceLoader.Save(tempFilename, Direct3D.ImageFileFormat.Png, tempSurface)

You can easily converted that do any programming language of you choice, it's basically calling Direct3d's API. Though, you need to configure you backbuffer and Present parameters as

' Need to use flip to enable screen capture
presentParams.SwapEffect = Direct3D.SwapEffect.Flip 
presentParams.PresentationInterval = Direct3D.PresentInterval.One

OTHER TIPS

Install a VM and run the application in that. If you're running a screen saver I doubt your video card is even generating the GUI for the application.

If I understand correct, all you want to to is take a screen grab of a specific application and not have the result be affected by a possibly running screensaver? As far as I know, simply doing GetDIBits on the HDC of the correct window should do the trick and not care about the screensaver.

You might find this code to be really slow, however you can get a massive speedup by setting the PresentParams.PresentFlag = PresentFlag.LockableBackBuffer

Also, you don't need to set PresentInterval.One or SwapEffect.Flip, they can be left at .Default and .Discard repsectively.

(Note that this speedup does not work if you are using multisampling, be sure that PresentParams.Multisample = Multisample.None . If you have an Nvidia card you can still get antialiasing by setting the option in the Nvidia control panel to override the application setting to what you want!)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top