Capture Screen and store it in a buffer C++ on Windows ----------------------------------Source.cpp---------------------- #include <Windows.h> #include <iostream> #include <math.h> #include <stdio.h> using namespace std; HBITMAP GetScreenBmp(HDC hdc) { // Get screen dimensions int nScreenWidth = GetSystemMetrics(SM_CXSCREEN); int nScreenHeight = GetSystemMetrics(SM_CYSCREEN); // Create compatible DC, create a compatible bitmap and copy the screen using BitBlt() HDC hCaptureDC = CreateCompatibleDC(hdc); HBITMAP hBitmap = CreateCompatibleBitmap(hdc, nScreenWidth, nScreenHeight); HGDIOBJ hOld = SelectObject(hCaptureDC, hBitmap); BOOL bOK = BitBlt(hCaptureDC, 0, 0, nScreenWidth, nScreenHeight, hdc, 0, 0, SRCCOPY | CAPTUREBLT); SelectObject(hCaptureDC, hOld); // always select the previously selected object once done DeleteDC(hCaptureDC); return hBitmap; } BYTE* get_screen_image(HDC hdc,HBITMAP hBitmap) { BITMAPINFO