利用IPersist接口可以实现保存HTML到文件,在VB和Delphi下的实现是这样的:
VB:
Dim oPF As IPersistFile
Set oPF = WebBrowser1.Document
oPF.Save "TheFileNameHere.htm", False
Delphi: uses MSHTML,OleCtrls, SHDocVw, StdCtrls,ActiveX; function GetHTMLCode(WB: IWebbrowser2; ACode: TStrings): Boolean; var ps: IPersistStreamInit; s: string; ss: TStringStream; sa: IStream; begin ps := WB.document as IPersistStreamInit; s := ''; ss := TStringStream.Create(s); try sa:= TStreamAdapter.Create(ss, soReference) as IStream; Result := Succeeded(ps.Save(sa, Bool(True))); if Result then ACode.Add(ss.Datastring); finally ss.Free; end; end;
至于VC下的实现方法,可以参考蒋晟的这篇文章:
http://www.csdn.net/develop/read_article.asp?id=18465
|