<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>DrawToDC</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx</link><description>I’m trying to take this code http://www.codeproject.com/internet/htmlimagecapture.asp?msg=783507 and convert it to C#. I can’t seem cast from IHTMLElement down to IHTMLElementRender. Trying through late binding also fails. IHTMLDocument2 doc = (IHTMLDocument2)Browser.Document;</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: DrawToDC</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#241006</link><pubDate>Tue, 12 Oct 2004 18:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:241006</guid><dc:creator>Geoff Appleby</dc:creator><description>Without actually going and trying it myself, i would hazard a guess that the IHTMLElementRender interface isn't an actual inherited interface of the body element.&lt;br&gt;&lt;br&gt;QueryInterface somtimes does more than just cast the object to a different interface, I'd make a bet that the QueryInterface for IHtmlElementRender is acting like a factory, and returning a new object. So therefore, when you just try and cast to that render interface, you get back null.&lt;br&gt;&lt;br&gt;Try calling QueryInterface directly on your body element, and see what that gives you. Let me know how you :)&lt;br&gt;&lt;br&gt;--Geoff</description></item><item><title>re: DrawToDC</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#241007</link><pubDate>Tue, 12 Oct 2004 18:11:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:241007</guid><dc:creator>Geoff Appleby</dc:creator><description>how you go, i mean to say.</description></item><item><title>re: DrawToDC</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#241097</link><pubDate>Wed, 13 Oct 2004 00:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:241097</guid><dc:creator>Darron</dc:creator><description>I tried this real quick and it works. I threw together a form with an IE control and a panel. There is an issue with import of the MSHTML interface so just redeclare it locally and you will have no problems. If render is null, you may have a frame to deal with.&lt;br&gt;&lt;br&gt;using System;&lt;br&gt;using System.Drawing;&lt;br&gt;using System.Runtime.InteropServices;&lt;br&gt;using SHDocVw;&lt;br&gt;using mshtml;&lt;br&gt;&lt;br&gt;namespace ScreenGrab&lt;br&gt;{&lt;br&gt;  [&lt;br&gt;  Guid(&amp;quot;3050f669-98b5-11cf-bb82-00aa00bdce0b&amp;quot;),&lt;br&gt;  InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown),&lt;br&gt;  ComVisible(true),&lt;br&gt;  ComImport&lt;br&gt;  ]&lt;br&gt;  interface IHTMLElementRender&lt;br&gt;  {&lt;br&gt;    void DrawToDC([In] IntPtr hDC);&lt;br&gt;    void SetDocumentPrinter([In, MarshalAs(UnmanagedType.BStr)] string bstrPrinterName, [In] IntPtr hDC); &lt;br&gt;  };&lt;br&gt;&lt;br&gt;  public class IEElementCapture&lt;br&gt;  {&lt;br&gt;    private IWebBrowser2 webBrowser = null;&lt;br&gt;&lt;br&gt;    public IEElementCapture(IWebBrowser2 webBrowser)&lt;br&gt;    {&lt;br&gt;      this.webBrowser = webBrowser;&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    public bool Capture(ref Graphics g)&lt;br&gt;    {&lt;br&gt;      if ( null == webBrowser )&lt;br&gt;      {&lt;br&gt;        return false;&lt;br&gt;      }&lt;br&gt;&lt;br&gt;      IHTMLDocument2 htmlDocument = (IHTMLDocument2) webBrowser.Document;&lt;br&gt;      if ( null != htmlDocument )&lt;br&gt;      {&lt;br&gt;        IHTMLElement bodyElement = (IHTMLElement) htmlDocument.body;&lt;br&gt;        if ( null != bodyElement )&lt;br&gt;        {&lt;br&gt;          IHTMLElementRender render = (IHTMLElementRender) bodyElement;&lt;br&gt;          if ( null != render )&lt;br&gt;          {&lt;br&gt;            IntPtr memDC = g.GetHdc();&lt;br&gt;            render.DrawToDC(memDC);&lt;br&gt;            return true;&lt;br&gt;          }&lt;br&gt;        }&lt;br&gt;      }&lt;br&gt;&lt;br&gt;      return false;&lt;br&gt;    }&lt;br&gt;  } &lt;br&gt;}&lt;br&gt;</description></item><item><title>re: DrawToDC</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#241230</link><pubDate>Wed, 13 Oct 2004 09:12:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:241230</guid><dc:creator>Ryan</dc:creator><description>This is perfect.  Thank you.  It is interesting that it doesn't pick up the custom DHTML filters like the gradients applied on www.microsoft.com home page.</description></item><item><title>re: DrawToDC</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#254514</link><pubDate>Wed, 10 Nov 2004 12:05:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:254514</guid><dc:creator>dd</dc:creator><description>Is there a VB.net version of this code?</description></item><item><title>[How To] Generate an image of a web page</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#411585</link><pubDate>Mon, 25 Apr 2005 06:09:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:411585</guid><dc:creator>Alan Dean</dc:creator><description>[How To] Generate an image of a web page</description></item><item><title>DrawToDC</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#6540393</link><pubDate>Tue, 27 Nov 2007 05:56:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6540393</guid><dc:creator>DrawToDC</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://feeds.maxblog.eu/item_351355.html"&gt;http://feeds.maxblog.eu/item_351355.html&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>Actors and Actresses  &amp;raquo; Archive du blog   &amp;raquo; Ryan Farber&amp;#8217;s WebLog : DrawToDC</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#6982845</link><pubDate>Fri, 04 Jan 2008 23:09:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6982845</guid><dc:creator>Actors and Actresses  » Archive du blog   » Ryan Farber’s WebLog : DrawToDC</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://actors.247blogging.info/?p=4029"&gt;http://actors.247blogging.info/?p=4029&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>html to image | FreeLance Home Jobs</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#8964444</link><pubDate>Thu, 25 Sep 2008 06:14:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8964444</guid><dc:creator>html to image | FreeLance Home Jobs</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.freelance-home-jobs.com/visual-basic/html-to-image/"&gt;http://www.freelance-home-jobs.com/visual-basic/html-to-image/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> Ryan Farber s WebLog DrawToDC | work from home</title><link>http://blogs.msdn.com/rfarber/archive/2004/10/12/240943.aspx#9760638</link><pubDate>Tue, 16 Jun 2009 14:31:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9760638</guid><dc:creator> Ryan Farber s WebLog DrawToDC | work from home</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://workfromhomecareer.info/story.php?id=16104"&gt;http://workfromhomecareer.info/story.php?id=16104&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>