What is the best way to take screenshots of a Window with C++ in Windows?

What is the best (easiest) way to take a screenshot of an running application with C++ under Windows?

Answers


You have to get the device context of the window (GetWindowDC()) and copy image (BitBlt()) from it. Depending on what else you know about the application you will use different methods to find which window's handle to pass into GetWindowDC().


On the keybd_event function documentation it states that you can use it to take a screenshot and save it to the clipboard. For example:

keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_SILENT, 0);

In my version (Visual Studio 2005 help installed on my computer) it states that you can take a screenshot of the whole desktop by setting the second parameter to 0, or a screen shot of just the current application by setting it to 1.

Taking it out of the clipboard buffer is left as an exercise for the reader.

However I'd think carefully before doing this as it will turf whatever image data was already present in the clipboard.


Need Your Help

Trouble displaying 3D objects with UV mapping from 3DS Max with OpenGL ES

iphone android opengl-es 3d collada

I've managed to display OBJ and Collada files in Android using OpenGL ES but when UV mapped textures are added to the equation I experience some issues. The texture displays incorrectly and the ob...

Using QStandardItemModel like QStringListModel

qt qt4

I am trying to use QStandardItemModel to do the same thing as QStringListModel (just for practice):

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.