5,928
社区成员




implementation
uses ADODB_TLB, CDO_TLB,ComObj ;
{$R *.dfm}
procedure WB_SaveAs_MHT(WB: TWebBrowser; FileName: TFileName);
var
Msg: IMessage;
Conf: IConfiguration;
Stream: _Stream;
URL : widestring;
begin
if not Assigned(WB.Document) then Exit;
URL := WB.LocationURL;
Msg := CoMessage.Create;
Conf := CoConfiguration.Create;
try
Msg.Configuration := Conf;
Msg.CreateMHTMLBody(URL, cdoSuppressImages, '', '');//cdoSuppressNone,cdoSuppressImages,cdoSuppressAll
Stream := Msg.GetStream;
Stream.SaveToFile(FileName, adSaveCreateOverWrite);
finally
Msg := nil;
Conf := nil;
Stream := nil;
end;
end; (* WB_SaveAs_MHT *)
procedure TForm1.Button1Click(Sender: TObject);
var
f:string;
begin
f:=ExtractFilePath(Application.ExeName)+'WebDoc.htm';
webbrowser1.Navigate(f);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
f1:string;
begin
f1:=ExtractFilePath(Application.ExeName)+'1.mht';
WB_SaveAs_MHT(webbrowser1,f1);
end;