Skip to content

Instantly share code, notes, and snippets.

@holmesconan
Created August 28, 2015 12:44
Show Gist options
  • Save holmesconan/23fdbd3ce16ee411f885 to your computer and use it in GitHub Desktop.
Save holmesconan/23fdbd3ce16ee411f885 to your computer and use it in GitHub Desktop.
Capture screen by GDI on Windows
HDC hdc = GetDC(NULL); // get the desktop device context
HDC hDest = CreateCompatibleDC(hdc); // create a device context to use yourself
// get the height and width of the screen
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
// create a bitmap
HBITMAP hbDesktop = CreateCompatibleBitmap( hdc, width, height);
// use the previously created device context with the bitmap
SelectObject(hDest, hbDesktop);
// copy from the desktop device context to the bitmap device context
// call this once per 'frame'
BitBlt(hDest, 0,0, width, height, hdc, 0, 0, SRCCOPY);
// after the recording is done, release the desktop context you got..
ReleaseDC(NULL, hdc);
// ..and delete the context you created
DeleteDC(hDest);
@quasar9090
Copy link

@alokmahor replace the first NULL by the HWND of calculator and get the RECT of the Calculator window

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment