in case you do not want to worry about clicking the link
#include <windows.h>
bool SaveBMPFile(char *filename, HBITMAP bitmap, HDC bitmapDC, int width, int height);
bool ScreenCapture(int x, int y, int width, int height, char *filename){
HDC hDc = CreateCompatibleDC(0);
HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height);
SelectObject(hDc, hBmp);
BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY);
bool ret = SaveBMPFile(filename, hBmp, hDc, width, height);
DeleteObject(hBmp);
return ret;
}
main(){
ScreenCapture(500, 200, 300, 300, "testScreenCap.bmp");
system("pause");
}
source
share