How to take Screen shot using C++

Hi,
I want to take screen shot and save it in any image format like jpg, bmp, ppm or any other . Please help me as soon as possible.
A screen shot of the current capture of your video card, or a screen shot of your programs current state?

If it's the latter, then you just need to pull the current screen surface or render capture, copy it to a buffer, convert to whatever format you want with the tools provided by the API you're working with (Open[el/al/gl], direct3d, sdl, etc etc) then write it to a file.

If it's the former, you would probably need to use a OS or driver specific api to intercept the current frame. for windows, you could look through the msdn.

P.S. I'm not very experienced in this kind of thing, this is just my theory and figured I'd share since there's no other post.
Last edited on
There is a way to do it using a cross-platform library/framework called Qt, apparently. The docs I have are for Qt 4.8, but it should work in Qt 5 as well.
http://qt-project.org/doc/qt-4.8/desktop-screenshot.html

Alternatively, here's a Stack Overflow for how to do it using the WinAPI (Windoze only):
http://stackoverflow.com/questions/3291167/how-to-make-screen-screenshot-with-win32-in-c

-Albatross
Last edited on
A really dumb way is to move the cursor and click each button of opening and using snipping tool. LOL

1
2
3
4
5
6
7
8
9
10
11
12
#include <windows.h>

int main(){
    //move cursor
    SetCursorPos(x,y);

    //click
    //mousedown
    mouse_event(MOUSEEVENTF_LEFTDOWN,x,y,0,0);
    //mouse up
    mouse_event(MOUSEEVENTF_LEFTUP,x,y,0,0);
}
Topic archived. No new replies allowed.