Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any Win32 APIs to get the screenshots? [duplicate]

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

like image 985
mgiza Avatar asked Feb 10 '09 09:02

mgiza


4 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().

like image 122
sharptooth Avatar answered Oct 28 '22 14:10

sharptooth


GetDC(NULL) + BitBlt()

To capture translucent/alpha/layered windows, you must pass the CAPTUREBLT flag to BitBlt, if you do that, the cursor blinks, read this technet article to find out why.

On NT6+, you might be able to use the Magnification API to do what you want.

like image 30
Anders Avatar answered Oct 28 '22 14:10

Anders


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.

like image 3
Daemin Avatar answered Oct 28 '22 14:10

Daemin


Here is an example code
You can do CaptureAnImage(GetDesktopWindow()); to make a screen capture.

like image 3
sflee Avatar answered Oct 28 '22 12:10

sflee