API capte l'écran

Signaler
-
 Polykos -
Salut,
Je cherche une fonction API qui capte le contenu de l'écran.

1 réponse

Tiens mets ce code avec filename le nom de ton fichier où sera enregistrer ta capture d'écran

Sous Visual C++ met doit fonctionner sur Borland c++

void ScreenCapture(char* filename)
{

// prepare DCs, bitmaps,..
HDC hScreenDC = GetWindowDC(0);
HDC hmemDC = CreateCompatibleDC(hScreenDC);
int ScreenWidth = GetDeviceCaps(hScreenDC, HORZRES);
int ScreenHeight = GetDeviceCaps(hScreenDC, VERTRES);
HBITMAP hmemBM = CreateCompatibleBitmap(hScreenDC, ScreenWidth, ScreenHeight);
SelectObject(hmemDC, hmemBM);

// copy screen to memory DC
BitBlt(hmemDC, 0, 0, ScreenWidth, ScreenHeight, hScreenDC, 0, 0, SRCCOPY);

// allocate and lock memory for the bitmap data
HGLOBAL hpxldata = GlobalAlloc(GMEM_FIXED, ScreenWidth * ScreenHeight * 3);
void FAR* lpvpxldata = GlobalLock(hpxldata);

// fill .bmp - structures
BITMAPINFO bmInfo;
bmInfo.bmiHeader.biSize = 40;
bmInfo.bmiHeader.biWidth = ScreenWidth;
bmInfo.bmiHeader.biHeight = ScreenHeight;
bmInfo.bmiHeader.biPlanes = 1;
bmInfo.bmiHeader.biBitCount = 24;
bmInfo.bmiHeader.biCompression = 0;
bmInfo.bmiHeader.biSizeImage = 0;
bmInfo.bmiHeader.biXPelsPerMeter = 0;
bmInfo.bmiHeader.biYPelsPerMeter = 0;
bmInfo.bmiHeader.biClrUsed = 0;
bmInfo.bmiHeader.biClrImportant = 0;

BITMAPFILEHEADER bmFileHeader;
bmFileHeader.bfType = 19778;
bmFileHeader.bfSize = (ScreenWidth * ScreenHeight * 3) + 40 + 14;
bmFileHeader.bfReserved1 = 0;
bmFileHeader.bfReserved2 = 0;
bmFileHeader.bfOffBits = 54;

// copy bitmap data into global memory
GetDIBits(hmemDC, hmemBM, 0, ScreenHeight, lpvpxldata, &bmInfo, DIB_RGB_COLORS);

// open file and write data
int bmfile = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IWRITE);
write(bmfile, &bmFileHeader, 14);
write(bmfile, &bmInfo, 40);
write(bmfile, lpvpxldata, ScreenWidth * ScreenHeight * 3);

// clean up
close(bmfile);
GlobalUnlock(hpxldata);
GlobalFree(hpxldata);
DeleteObject(hmemBM);
DeleteDC(hmemDC);
ReleaseDC(0, hScreenDC);
}