jondinham
jondinham

Reputation: 8511

Fast way to get screenshot of Windows application in C++ (Win32)?

I'm facing a problem when my application needs to get screenshots of other Windows applications.

I'm using the function in win32api 'PrintWindow', but this doesn't work well. It is slow and some components inside other applications' windows shown as black rectangles.

There is an application (Mac-OS-style task switcher) called DExpose2 by Devrexster. It can get the screenshots of other applications really fast, damn fast, even it can get these screenshots continuously.

I guess it is using Direct3D to get screenshots of applications instead of using GDI as I'm using. Is it possible to to use Direct3D for this purpose? and if possible, which should be the neatest way?

Upvotes: 5

Views: 6088

Answers (2)

MSalters
MSalters

Reputation: 179779

The answer for Vista+ is in another answer : snoop on DirectX's buffer.

DExpose2 probably doesn't "get" the screenshots. I.e. it doesn't transfer them from the videocard to RAM. That's a slow operation, and would have to be followed by another slow copy back to the videocard. I expect that it just applies a few scale and move transforms on the videocard side, with no pixels or texels crossing the PCI-e bus.

Upvotes: 4

Michael
Michael

Reputation: 637

You can use bitblt to get a screenshot. Here's an example of getting it for the entire desktop:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd183402(v=vs.85).aspx

You probably need to adjust the X, Y, and size parameters so that you get a subset, corresponding to just the window you care about.

Upvotes: 2

Related Questions