Programming magic, glory, and juices.

IHTMLElementRender opacity

June 9th, 2006


Using IHTMLElementRender::DrawToDC is the wrong way to draw the contents of an webpage to a device drawing context. The reason why the IHTMLElementRender interface is not good is because it does not draw opacity or transpancy that might be visible in a web page. Instead it is best to query the IViewObject interface from the IHTMLDocument2 interface and call the function Draw.

BAD
IHTMLDocument2 — IHTMLElement – IHTMLElementRender::DrawToDC.

GOOD
IHTMLDocument2 – IViewObject::Draw using DVASPECT_DOCPRINT

One thing that is noteworthy is that the call to IViewObject::Draw fails if you implement DISPID_BEFORENAVIGATE2.

You can also use OleDraw instead of IViewObject::Draw and pass OleDraw the IHTMLDocument2 interface.

3 Responses to “IHTMLElementRender opacity”
  1. Wayne Hoit Says:

    I don’t suppose you can help me figure out how to draw an HTML page “into” an Enhanced Metafile using VB 6 ?

  2. Anony Says:

    YOU A GENIUS!!!!

  3. WebBrowser control...again about web sites thumbnails/screenshots generated from the server Says:

    [...] it and that’s why my image was missing some parts. I’ve found the solution from an old post from Nathan Moinvaziri. So, I implemented his easy solution that is to use IViewObject instead of IHTMLElementRender… [...]

Leave a Reply