Article View: borland.public.cppbuilder.internet.web
Article #1623Re: TCppWebBrowser and Framed HTML Pages
From: Remy Lebeau (TeamB)
Date: Thu, 04 Nov 2004 01:06
Date: Thu, 04 Nov 2004 01:06
80 lines
3108 bytes
3108 bytes
"Saulo I. Regis" <saulo@password.info> wrote in message
news:418972c3$1@newsgroups.borland.com...
> Could you give me a small sample code of how I access
> the frames collection, scan it and retrieve the HTML code
> of each frame?
I take it that you did not read the documentation for IHTMLDocument2 yet,
did you?
http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/interface.asp
#include <memory>
#include <utilcls.h>
void __fastcall GetFramesHTML()
{
if( !Browser1->Document ) return;
TComInterface<IHTMLDocument2> Doc;
Browser1->Document->QueryInterface(IID_HTMLDocument2,
(LPVOID*)&Doc);
if( !Doc ) return;
TComInterface<IHTMLFramesCollection2> Frames;
Doc->get_frames(&Frames);
if( !Frames ) return;
long cnt = 0;
Frames->get_length(&cnt);
for(long l = 0; l < cnt; ++l)
{
TVariant idx = l;
TVariant ret;
Frames->item(&idx, &ret);
if( (ret.vt != VT_DISPATCH) || (ret.pdispVal == NULL) )
continue;
TComInterface<IHTMLWindow2> Window;
ret.pdispVal->QueryInterface(IID_IHTMLWindow2,
(LPVOID*)&Window);
if( !Window ) continue;
TComInterface<IHTMLDocument2> Doc2;
Window->get_document(&Doc2);
if( !Doc2 ) continue;
AnsiString HTML = GetHTML(Doc2);
if( !HTML.IsEmpty() )
// use HTML as needed...
}
}
AnsiString __fastcall GetHTML(IHTMLDocument2* Doc)
{
if( Doc )
{
TComInterface<IPersistStreamInit> Psi;
Doc->QueryInterface(IID_IPersistStreamInit, (LPVOID*)&Psi);
if( Psi )
{
std::auto_ptr<TStringStream> StrStrm(new TStringStream(""));
std::auto_ptr<TStreamAdapter> Adapter(new
TStreamAdapter(StrStrm.get(), soReference));
if( SUCCEEDED(Psi->Save(*Adapter, FALSE)) )
return StrStrm->DataString;
}
}
return "";
}
Gambit
Technical Details
Message-ID:
<4189803d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<418954e8@newsgroups.borland.com> <41896e7a$1@newsgroups.borland.com> <418972c3$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,2f5b16c00db0b7f3 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.web References: <418954e8@newsgroups.borland.com> <41896e7a$1@newsgroups.borland.com> <418972c3$1@newsgroups.borland.com> Subject: Re: TCppWebBrowser and Framed HTML Pages Date: Wed, 3 Nov 2004 17:06:12 -0800 Lines: 82 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4189803d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1099530301 68.69.17.41 (3 Nov 2004 17:05:01 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail