这是我目前的职能:
#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);
}
我的目标是创建一个函数,在调用时,获取屏幕截图并将其数据保存到缓冲区。 我的问题:使用ON32 win32 api将保存到缓冲区的最有效方法是什么? (添加到缓冲区是代码中唯一缺少的部分)。