注册 | 登录
收藏 | 帮助
热门文章
编辑推荐
相关文章  
IMail的解惑篇--第五节 常用We
IMail的解惑篇--第六节 常用We
IMail常用Web页面的汉化
为imail和Mdaemon设计Webmail---
SQL Server静态页面导出技术1
SQL Server静态页面导出技术2
在SQL Server中保存和输出图片
如何向SQL Server中保存bmp图象以
从Access数据库恢复BMP图像并显示
在IE页面中使用MSChart控件(版本
您现在的位置: 顶尖设计 >> IT学院 >> 编程开发 >> Delphi >> 文章正文
保存页面为MHT的代码
作者:TechnoFantasy  来源:csdn  点击:  更新:2006-12-19
简介:
 

Here's how to save a web page as a single file (mht format) using Delphi code:

uses CDO_TLB, ADODB_TLB;

...

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, cdoSuppressAll, '', '');

    Stream := Msg.GetStream;

    Stream.SaveToFile(FileName, adSaveCreateOverWrite);

  finally

    Msg := nil;

    Conf := nil;

    Stream := nil;

  end;

end; (* WB_SaveAs_MHT *)



Sample usage:

  //first navigate

  WebBrowser1.Navigate('http://delphi.about.com');

  

  //then save

  WB_SaveAs_MHT(WebBrowser1,'c:\WebBrowser1.mht');



Note 1: The _Stream class is defined in ADODB_TLB unit that you probably already have created. The IMessage and IConfiguration interfaces code from cdosys.dll library. CDO stands for Collaboration Data Objects - object libraries designed to enable SMTP Messaging.
The CDO_TLB is an auto generated unit by Delphi. To create it, from the main menu select "Import Type Library", select "C:\WINDOWS\system32\cdosys.dll" then click the "Create unit" button.






  • 上一篇文章:
  • 下一篇文章:
  • 分享此文:该页面添加到 Mister Wong 添加到雅虎Yahoo!收藏 Add to:Del.icio.us Post to Furl Digg this 添加到Google书签 reddit spurl blogmarks 365Key 评论  收藏  分享  打印
     我来说两句
    姓名:       验证码:   
    主页: 
    评分: 1分 2分 3分 4分 5分
    本频道近期热评文章:
      关于我们 | 联系我们 | 站点地图 | 广告投放 | 友情链接 | 在线留言 | 版权申明
    版权所有 © 2004-2007 顶尖设计(bobd.cn)
    未经授权禁止转载,摘编,复制本站内容或建立镜像. 沪ICP备07504942号 
    网络110
    报警服务