Article View: borland.public.cppbuilder.internet.web
Article #1329Re: Saving a Web Page from TCcpbrowser without a dialog
From: murone
Date: Fri, 25 Mar 2005 17:39
Date: Fri, 25 Mar 2005 17:39
167 lines
5939 bytes
5939 bytes
For anyone interested, here is the solution...
�ĵ����⣺��ΰ�һ����ҳ��Ϊһ��������mht�ļ��������ߣ� ccrun
�� �� �֣���ҳ,mht,outlook,COM,CDO,�ӿ�,CreateMHTMLBody,ccrun
����ת�� C++Builder �о� -
http://www.ccrun.com/article/go.asp?i=615&d=l77p38
#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"));
}
--------------------------------------------------------------------------------
>>��ƪ����: ����Shell�������Windowsϵͳ
>>��ƪ����: Windows�ļ�������Ӧ��
"murone" <banterbubba@yahoo.com> wrote in message
news:42441526$1@newsgroups.borland.com...
> The following code is what I want to do, but I don't know enough about
> Pascal to convert it to C++. Any sharp Delphi coders willing to help out?
> Thanks
>
> 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 *)
> "murone" <banterbubba@yahoo.com> wrote in message
> news:4242dbbc@newsgroups.borland.com...
>>I am trying to save a Web page from tccpbrowser. If I use the code below,
>>it works fine, but explorer handles it and pops up a dialog box. I also
>>have code below that which will display the source, and then can be saved.
>>My question is how do I save the complete page to include images, without
>>showing a dialog box to the user?
>>
>> Thanks,
>>
>> ba
>>
>> PROMPTS USER WITH DIALOG BOX:
>> AnsiString FileName = ExtractFilePath ( ParamStr (0) )
>> + "ExecWB.OLECMDID_SAVEAS.html";
>>
>> char filename [MAXPATH];
>>
>> strcpy ( filename, FileName.c_str() );
>>
>> TVariant Variant = filename;
>>
>> CppWebBrowser1->ExecWB(
>> Shdocvw_tlb::OLECMDID_SAVEAS,
>> Shdocvw_tlb::OLECMDEXECOPT_DODEFAULT, &Variant );
>>
>>
>>
>> DISPLAYS HTML SOURCE:
>> AnsiString Source = "";
>>
>> IHTMLDocument2 *htm = NULL; // #include <mshtml.h>
>>
>>
>>
>> if(CppWebBrowser1->Document&&SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&htm)))
>> {IPersistStreamInit *spPsi = NULL; // ocidl.h
>>
>>
>> if(SUCCEEDED(htm->QueryInterface(IID_IPersistStreamInit,(LPVOID*)&spPsi))
>> && spPsi)
>> {IStream *spStream = NULL; // objidl.h
>> OleCheck(CreateStreamOnHGlobal(NULL, true, &spStream));
>> if(spStream)
>> {__int64 nSize = 0;
>> STATSTG ss;
>> LARGE_INTEGER nMove;
>> nMove.QuadPart = 0;
>> OleCheck(spPsi->Save(spStream, true));
>> OleCheck(spStream->Seek(nMove,STREAM_SEEK_SET,(ULARGE_INTEGER
>> *)&nSize));
>> OleCheck(spStream->Stat(&ss, STATFLAG_NONAME));
>> nSize = ss.cbSize.QuadPart;
>>
>> Source.SetLength(nSize);
>> OleCheck(spStream->Read((void *)Source.data(),
>> nSize,(ULONG*)&nSize));
>> OleCheck(spStream->Release());
>> }
>>
>> spPsi->Release();
>> }
>> htm->Release();
>> }
>>
>>
>
>
Technical Details
Message-ID:
<42444cbf$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4242dbbc@newsgroups.borland.com> <42441526$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,17dd1985d663bc5a X-Google-Attributes: gidfeeec,public X-Google-Language: Chinese,GB From: "murone" <banterbubba@yahoo.com> Newsgroups: borland.public.cppbuilder.internet.web References: <4242dbbc@newsgroups.borland.com> <42441526$1@newsgroups.borland.com> Subject: Re: Saving a Web Page from TCcpbrowser without a dialog Date: Fri, 25 Mar 2005 12:39:10 -0500 Lines: 169 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 67.165.45.154 Message-ID: <42444cbf$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1111772351 67.165.45.154 (25 Mar 2005 09:39:11 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!newshub.sdsu.edu!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail