56 lines
1.2 KiB
C#
56 lines
1.2 KiB
C#
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;
|
|
}
|
|
}
|
|
} |