Thread View: borland.public.cppbuilder.internet.web
3 messages
3 total messages
Started by murone
Thu, 24 Mar 2005 15:24
Saving a Web Page from TCcpbrowser without a dialog
Author: murone
Date: Thu, 24 Mar 2005 15:24
Date: Thu, 24 Mar 2005 15:24
60 lines
2641 bytes
2641 bytes
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();
}
Re: Saving a Web Page from TCcpbrowser without a dialog
Author: murone
Date: Fri, 25 Mar 2005 13:41
Date: Fri, 25 Mar 2005 13:41
94 lines
3761 bytes
3761 bytes
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();
> }
>
>
Re: Saving a Web Page from TCcpbrowser without a dialog
Author: 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();
>> }
>>
>>
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads