🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #1327

Re: Saving a Web Page from TCcpbrowser without a dialog

#1327
From: murone
Date: Fri, 25 Mar 2005 13:41
94 lines
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();
> }
>
> 
Technical Details
Message-ID: <42441526$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!mpls-transit-01.news.qwest.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <4242dbbc@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,17dd1985d663bc5a
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "murone" <banterbubba@yahoo.com>
Newsgroups: borland.public.cppbuilder.internet.web
References: <4242dbbc@newsgroups.borland.com>
Subject: Re: Saving a Web Page from TCcpbrowser without a dialog
Date: Fri, 25 Mar 2005 08:41:58 -0500
Lines: 96
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: <42441526$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1111758118 67.165.45.154 (25 Mar 2005 05:41:58 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!mpls-transit-01.news.qwest.net!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail