I'm interested in the render output from a WebBrowser ActiveX control. That WebBrowser is running in-process. The idea is to obtain a "screenshot" of what the control is showing. In other words: get the WebBrowser pixels.
What is currently the best practice to do so?
Because after some small research I found there are at least 5 ways to achieve this:
- The
IHTMLElementRenderer::DrawToDC
method. - The
IViewObject2::Draw
route. - The
OleDraw
route. To me, this just seems a short hand for method 2. - The
PrintWindow
Windows API function. Delivers the correct result, but fails when the Window with the WebBrowser control is invisible (WS_VISIBLE
style missing) - Capture the desktop and crop to the area where the webbrowser control is showing
The first method looks most promising. However, according to the documentation, it is deprecated, so I guess I can't rely on it anymore?
Notes:
- If the page is bigger than the window/viewport, then it's not a problem that those pixels are missing (the pages I'd like to capture are of a fixed size)
- I have seen the IE feature
FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI
, but this seem to matter only for programs that want Windows Metafile (WMF) output. A bitmap is fine for me. - Other windows should not be visible on the end result
- When I first called
DrawToDC
I ended up with a completely black bitmap. Later it turns out this happened because my bitmap was 1-bit monochrome. That's the default for a bitmap apparently: I fell into an old GDI trap!