【问题标题】:Render chrome with PrintWindow使用 PrintWindow 渲染 chrome
【发布时间】:2018-12-09 16:04:36
【问题描述】:

我正在尝试使用 PrintWindow 让 chrome 在我的画布上绘画。这是我用来呈现桌面捕获的代码

PRECT lpRect;
GetWindowRect(g_Window, lpRect);

HDC hDeviceContext    =
   CreateCompatibleDC(g_DeviceContextMain);
HBITMAP hBitmapWindow = 
   CreateCompatibleBitmap(g_DeviceContextMain, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top);

SelectObject(hDeviceContext, hBitmapWindow);
if (PrintWindow(g_Window, hDeviceContext, g_IsAtleast81 ? 0x00000002 : NULL)) {
    BitBlt(g_DeviceContextClient, 
       lpRect->left, lpRect->top, lpRect->right - lpRect->left, lpRect->bottom - lpRect->top, hDeviceContext, NULL, NULL, SRCCOPY);
}

DeleteObject(hBitmapWindow);
DeleteDC(hDeviceContext);

这是我打开 chrome 并捕获屏幕时的输出(Windows 7)

我可以在 Windows 10 中通过将 PW_RENDERFULLCONTENT 标志添加到 PrintWindow 来解决此问题,但不幸的是,此标志仅在 Windows 8.1 及更高版本中可用。我需要让它在 Windows 7/8 中工作。

在捕获屏幕之前,我还尝试在 chrome 中禁用硬件加速。结果还是一样!

我有什么办法可以解决这个问题,比如主窗口的绘制没有黑色矩形?或者复制 PW_RENDERFULLCONTENT 在 Windows = 8.1 所做的操作?

【问题讨论】:

    标签: c google-chrome winapi


    【解决方案1】:

    您可能无法使用 PrintWindow 打印 chrome 窗口,但您可以使用 BitBlt。该函数只会获取屏幕的一部分,因此您无法获取最小化窗口的位图,这与 PrintScreen 不同。

    BitBlt Docs

    以及它是如何在 webrtc 中实现的: https://cs.chromium.org/chromium/src/third_party/webrtc/modules/desktop_capture/window_capturer_win.cc

    【讨论】:

    • 这是可以接受的,但是在我的应用程序中,用户可以选择监视他计算机上的任何桌面。如果我们谈论的是像WinSta0 这样的当前桌面,那么这个答案是可以接受的。但是,我不能接受这一点,我也尝试使用BitBlt,如果桌面不是当前桌面,它没有捕获屏幕。
    • 我试图在问题中找到施加所有额外限制的文本。我看不到它。发生这种情况时,回答者会感到沮丧。
    猜你喜欢
    • 2013-01-03
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 2020-11-15
    • 2019-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多