PrintWindow and Microsoft Edge

2019-08-14 20:42发布

问题:

we have a problem with the PrintWindow function on Windows 10 (build 10166). When we call PrintWindow (https://msdn.microsoft.com/ru-ru/library/windows/desktop/dd162869(v=vs.85).aspx) to capture a image of the Microsoft Edge (Project Spartan) browser window we get a black image.

Does anyone know the reason of this and how could it be fixed/avoided? Or maybe some other way to capture image of a window, that can be in background and hided behind another windows?

UPDATE: We've tried sending WM_PRINTCLIENT and WM_PRINT messages, and calling DefWindowProc with WM_PRINT, but results are the same - just a black image. We also tried to use BitBlt to copy window's DC to a memory surface, but it's not working too. Best solution that we have now is bringing browser window to foreground, capturing the entire screen and cropping screenshot to window's client size; but it can interrupt and annoy users because of switching application that's currently in use.

回答1:

If you want to take a screenshot of the page on the browser. try this JavaScript library: http://html2canvas.hertzen.com/ The script traverses through the DOM of the page it is loaded on. It gathers information on all the elements there, which it then uses to build a representation of the page. In other words, it does not actually take a screenshot of the page, but builds a representation of it based on the properties it reads from the DOM.

I just tried on my machine on Microsoft Edge and Chrome and worked on both.Hope that does the job!



回答2:

I had the same problem with IE try this. The most stable result was with double call

PrintWindow(hWnd, hdcScreen, 0);
PrintWindow(hWnd, hdcScreen, PW_CLIENTONLY);