小编SYY*_*Y99的帖子

后台窗口的 C++ WinAPI 截图

我想截取一个没有焦点的窗口的屏幕截图。我的功能适用于某些窗口,但不适用于所有窗口,我不知道为什么。我试着用它来捕捉 Bluestacks App Player 的窗口,它运行得很好。但是对于 Nox App Player 和其他一些游戏,它根本不起作用。我只得到一个与窗口大小相同的黑色图像。

这是到目前为止的代码:

void screenshot_window(HWND handle) {
    RECT client_rect = { 0 };
    GetClientRect(handle, &client_rect);
    int width = client_rect.right - client_rect.left;
    int height = client_rect.bottom - client_rect.top;


    HDC hdcScreen = GetDC(handle);
    HDC hdc = CreateCompatibleDC(hdcScreen);
    HBITMAP hbmp = CreateCompatibleBitmap(hdcScreen, width, height);
    SelectObject(hdc, hbmp);

    BitBlt(hdc, 0, 0, width, height, hdcScreen, 0, 0, SRCCOPY);

    BITMAPINFO bmp_info = { 0 };
    bmp_info.bmiHeader.biSize = sizeof(bmp_info.bmiHeader);
    bmp_info.bmiHeader.biWidth = width;
    bmp_info.bmiHeader.biHeight = height;
    bmp_info.bmiHeader.biPlanes = 1;
    bmp_info.bmiHeader.biBitCount = 24; …
Run Code Online (Sandbox Code Playgroud)

c++ winapi screenshot

6
推荐指数
1
解决办法
5100
查看次数

标签 统计

c++ ×1

screenshot ×1

winapi ×1