What is the best (easiest) way to take a screenshot of an running application with C++ under Windows?
-
1This really helped: http://groups.google.com/group/win32-programming/browse_thread/thread/55c030edbaeaf026 – Microkernel Apr 09 '10 at 11:56
-
10How was this question off-topic? It's asking how to do it programmatically, which seems pretty relevant to me (and isn't too uncommon). – jamesdlin Mar 02 '13 at 08:52
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()
.

- 156,901
- 35
- 231
- 235

- 167,383
- 100
- 513
- 979
-
10please add more details about how to use GetWindowDC and BitBlt to get screenshot. i want the details also.... – jondinham Sep 03 '11 at 10:43
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.
-
Hi, Thanks for that. Now I remember, the one attempt I did which was causing the mouse pointer to blink was GetDC()+BitBlt(). Thats the main problem :( I don't want the pointer to blink... Any ways to get the screen shots seemlessly??? – Microkernel Apr 09 '10 at 11:44
-
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.

- 10,315
- 5
- 39
- 45
-
1that's the event for the PrintScr key on the keyboard. the 'keybd_event' you stated cannot be used to take screenshot. what a concept mis-understanding! – jondinham Sep 03 '11 at 10:41
-
3@Paul Follow the link I've included and check out the Remarks section. It states: "An application can simulate a press of the PRINTSCRN key in order to obtain a screen snapshot and save it to the clipboard. To do this, call keybd_event with the bVk parameter set to VK_SNAPSHOT." – Dominik Grabiec Sep 05 '11 at 08:36
-
oh ok i see, didn't know we could simulate the press of printscr key :) – jondinham Sep 05 '11 at 08:42