如何把一个网页存为一个单独的mht文件
2008-03-08 12:46:09 来源:WEB开发网核心提示:#include "SHDocVw_OCX.h"#include "cdoex.h"#include "msado15.h"using namespace CDO;// 本文是ccrun(老妖)根据相关资料改的,在BCB 6.0 下成功编译并测试通过.// 假
#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"));
}
#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"));
}
[]
更多精彩
赞助商链接