程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> 如何把一個網頁存為一個單獨的mht文件

如何把一個網頁存為一個單獨的mht文件

編輯:關於C++
#include "SHDocVw_OCX.h"
#include "cdoex.h"
#include "msado15.h"
using namespace CDO;
// 本文是ccrun(老妖)根據相關資料改的,在BCB 6.0 下成功編譯並測試通過.
// 如果有不能正常運行的,可能需要在機器上安裝有outlook.
void __fastcall SaveWholePage(BSTR bstrUrl, BSTR bstrFileName)
{
  CoInitialize(NULL);
  IMessage *pMsg;
  IConfiguration *pConfig;
  HRESULT hr = CoCreateInstance(__uuidof(Message), NULL,
      CLSCTX_INPROC_SERVER, __uuidof(IMessage), (void**)&pMsg);
  hr = CoCreateInstance(
    __uuidof(Configuration),
    NULL,
    CLSCTX_INPROC_SERVER,
    __uuidof(IConfiguration),
    (void**)&pConfig);
  pMsg->put_Configuration(pConfig);
  try<br>
  {
    pMsg->CreateMHTMLBody(
      bstrUrl,
      cdoSuppressNone,
      WideString(""),
      WideString(""));
  }
  catch(...)
  {
    ShowMessage("有錯誤發生!");
    return;
  }
  ADOStream *pStream;
  pMsg->GetStream(&pStream);
  pStream->SaveToFile(bstrFileName, adSaveCreateOverWrite);
  pMsg->Release();
  pStream->Release();
  CoUninitialize();
}
// 調用舉例:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  SaveWholePage(WideString("http://www.ccrun.com"),
      WideString("C:\\123.mht"));
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved