If you just want the content of the window: window.capture()
Your answers are SOOO "helpfull".
Solution to make a printscreen if fullscreen mode on windows :
void copyScreenshotToClipboard(const sf::Image & image)
{
BITMAPINFOHEADER bmpInfoHeader = {0};
bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfoHeader.biBitCount = 24;
bmpInfoHeader.biClrImportant = 0;
bmpInfoHeader.biClrUsed = 0;
bmpInfoHeader.biCompression = BI_RGB;
bmpInfoHeader.biHeight = image.getSize().y;
bmpInfoHeader.biWidth = image.getSize().x;
bmpInfoHeader.biPlanes = 1;
bmpInfoHeader.biSizeImage = image.getSize().x * image.getSize().y * 3;
HGLOBAL hResult;
if (!OpenClipboard(NULL)) return ;
if (!EmptyClipboard()) return ;
int size = sizeof(BITMAPINFOHEADER) + bmpInfoHeader.biSizeImage;
hResult = GlobalAlloc(GMEM_MOVEABLE, size);
if (hResult == NULL) return ;
void * pointer = GlobalLock(hResult);
memcpy(pointer, &bmpInfoHeader, sizeof(BITMAPINFOHEADER));
pointer = (void*) ((int)pointer + sizeof(BITMAPINFOHEADER));
const unsigned char * src = image.getPixelsPtr() + (image.getSize().y - 1) * image.getSize().x * 4;
unsigned char * dest = (unsigned char*)pointer;
unsigned int srcIndex = 0;
unsigned int dstIndex = 0;
for (unsigned int i = 0; i < image.getSize().y; i++) {
for (unsigned int j = 0; j < image.getSize().x; j++) {
dest[dstIndex + 0] = src[srcIndex + 2];
dest[dstIndex + 1] = src[srcIndex + 1];
dest[dstIndex + 2] = src[srcIndex + 0];
dstIndex += 3;
srcIndex += 4;
}
srcIndex = 0;
src -= image.getSize().x * 4;
if (image.getSize().x % 4 != 0) dstIndex += 4 - image.getSize().x % 4;
}
GlobalUnlock(hResult);
if (SetClipboardData(CF_DIB, hResult) == NULL) {
CloseClipboard();
return ; // error
}
CloseClipboard();
GlobalFree(hResult);
}
This will copy the content of image to clipbuffer, you can insert it to any other program (photoshop, paint, etc.)
To Handle print screen use :
GetAsyncKeyState(VK_SNAPSHOT)
call copyScreenshotToClipboard on the next iteration