#include <iostream>
#include <windows.h>
using namespace std;
int main() {
// The pixel we're scanning for
COLORREF tofind = RGB( 255, 0, 0 );
// Screen size
int screen_width = GetSystemMetrics( SM_CXSCREEN );
int screen_height = GetSystemMetrics( SM_CYSCREEN );
// Get HBITMAP from our HDC of the screen
HDC hdc = GetDC( NULL );
HDC hdcMem = CreateCompatibleDC( hdc );
HBITMAP bmp = CreateCompatibleBitmap( hdcMem, screen_width, screen_height );
SelectObject( hdcMem, bmp );
BitBlt( hdcMem , 0, 0, screen_width, screen_height, hdc, 0, 0, SRCCOPY );
// bmp now contains the screenshot
}