您的位置:首页 > 其它

Saving a Web Page Into A Single File

2007-04-05 08:54 351 查看
你是否曾经想过要把一个包含图片和文本的网页保存到单个的文件里?你可以使用IE的 saveAs 功能,但是缺点很明显,这个Saveas 对话框总是出于安全考虑而被show up.有重复杂的做法,可以避开 SaveAs 对话框。下面我给大家示范如何操作:

Do you ever want to save a web page into one single file, including pictures and text? You can use IE SaveAs command, but the drawback is obvious, the Save As dialog is always shown up for security reason. There is a complicated work around to avoid the Save As dialog (see Automated IE SaveAs MHTML). Here I show you an easy way to do it:

#import "c:/program files/common files/system/ado/msado15.dll" _
        no_namespace rename("EOF", "EndOfFile")
#import  no_namespace rename("EOF", "EndOfFile")

...

void SaveWholePage(LPCTSTR page_url,LPCTSTR save_filename)
{
   CoInitialize(NULL);
   {
      IMessagePtr       iMsg(__uuidof(Message));
      IConfigurationPtr iConf(__uuidof(Configuration));
      iMsg->Configuration = iConf;
      try
      {
         iMsg->CreateMHTMLBody(
            page_url,
            cdoSuppressNone,
            "domain//username",
            "password");
      }
      catch(_com_error err)
      {
         // handle exception
      }
      _StreamPtr pStream=iMsg->GetStream();
      pStream->SaveToFile( save_filename,
                           adSaveCreateOverWrite);
   }
   CoUninitialize();
}

简单的用法:

SaveWholePage("http://www.zaobao.com/gj/zg002_050203.html",
              "test.mht");

我们不提供例子程序,你可以把这段代码复制粘贴到你自己创建的程序中去。

Sample program is not provided, since you can create it on your own and copy & paste the above code snippet into your project.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: