this is my current function:
#include <stdafx.h>
#include <windows.h>
void screenshot()
{
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
HWND hWnd = GetConsoleWindow(); //Retrieves the window handle used by the console associated with the calling process.
HDC hScreen = GetDC(hWnd); //possibly GetDC(NULL) instead? //Retrieves a handle to a device context (DC) for the client area of a specified window or for the entire screen.
HDC hDC = CreateCompatibleDC(hScreen); //Creates a memory device context (DC) compatible with the specified device.
HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, screenWidth, screenHeight); //the bitmap handle
SelectObject(hDC, hBitmap);
BitBlt(hDC, 0, 0, screenWidth, screenHeight, hScreen, 0, 0, SRCCOPY | CAPTUREBLT); //Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
//...enter "save to buffer" code here...//
ReleaseDC(hWnd, hScreen);
DeleteDC(hDC);
DeleteObject(hBitmap);
}
My objective is to create a function that when called, takes a screenshot and saves its data to the buffer. my question: What is the most efficient way to save it to the buffer, using ONLY win32 api? (add to buffer is the only part missing in the code).