Render chrome with PrintWindow

-1

I am trying to get chrome to paint on my canvas using PrintWindow. Here is the code I use to render the desktop capture

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);

Here is the output when I open chrome and capture the screen (Windows 7)

1

I can fix this in Windows 10 by adding the PW_RENDERFULLCONTENT flag to PrintWindow but unfortunately this flag is only available in Windows 8.1 and up. I need to get this to work in Windows 7/8.

I also tried disabling hardware acceleration in chrome, prior to capture the screen. The result was still the same!

Any way I can go about fixing this issue, such that the main window is drawn without a black rectangle? Or replicate what PW_RENDERFULLCONTENT does with Windows >= 8.1 in Windows < 8?

c
google-chrome
winapi
asked on Stack Overflow Jun 30, 2018 by bob willis • edited Jun 30, 2018 by bob willis

1 Answer

0

You probably can't print the chrome window using PrintWindow, but what you may do is using BitBlt. The function will only get parts of the screen, therefore you can't get the bitmap of a minimized window, unlike PrintScreen.

BitBlt Docs

and how it was implemented in webrtc: https://cs.chromium.org/chromium/src/third_party/webrtc/modules/desktop_capture/window_capturer_win.cc

answered on Stack Overflow Jun 30, 2018 by Hagai Wild

User contributions licensed under CC BY-SA 3.0