// create a DC for the screen and create
// a memory DC compatible with screen DC
HDC hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
HDC hMemDC = CreateCompatibleDC(hScrDC);
// create a bitmap compatible with the screen DC
HBITMAP hBitmap = CreateCompatibleBitmap(hScrDC, width, height);
// select new bitmap into memory DC
(HBITMAP*)SelectObject(hMemDC, hBitmap);
// copy pixel data from screen DC to memory DC
BitBlt(hMemDC, origX, origY, width, height, hScrDC, srcOrigX, srcOrigY, SRCCOPY);
BITMAP bmp;
// get updated bitmap back
GetObject(hBitmap, sizeof(BITMAP), &bmp);
BITMAPINFO bi;
// get pixel data in RGB format
// bi struct specifies the format data
// pdata will hold pixel data
GetDIBits(hMemDC, hBitmap, 0, height, pdata, &bi, DIB_RGB_COLORS);