This commit is contained in:
2014-10-16 09:18:12 +00:00
parent cbee8b92bf
commit c5054a8c64
5 changed files with 266 additions and 51 deletions

56
IHTMLElementRender.cs Normal file
View File

@@ -0,0 +1,56 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using SHDocVw;
using mshtml;
namespace CyworldDownloader
{
[
Guid("3050f669-98b5-11cf-bb82-00aa00bdce0b"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown),
ComVisible(true),
ComImport
]
interface IHTMLElementRender
{
void DrawToDC([In] IntPtr hDC);
void SetDocumentPrinter([In, MarshalAs(UnmanagedType.BStr)] string bstrPrinterName, [In] IntPtr hDC);
};
public class IEElementCapture
{
private IWebBrowser2 webBrowser = null;
public IEElementCapture(IWebBrowser2 webBrowser)
{
this.webBrowser = webBrowser;
}
public bool Capture(ref Graphics g)
{
if(null == webBrowser)
{
return false;
}
IHTMLDocument2 htmlDocument = (IHTMLDocument2)webBrowser.Document;
if(null != htmlDocument)
{
IHTMLElement bodyElement = (IHTMLElement)htmlDocument.body;
if(null != bodyElement)
{
IHTMLElementRender render = (IHTMLElementRender)bodyElement;
if(null != render)
{
IntPtr memDC = g.GetHdc();
render.DrawToDC(memDC);
return true;
}
}
}
return false;
}
}
}