Article View: borland.public.cppbuilder.internet.web
Article #860Detecting whether a web site contains frame
From: Mehmet Caner
Date: Fri, 13 Jan 2006 17:38
Date: Fri, 13 Jan 2006 17:38
84 lines
3628 bytes
3628 bytes
Hi,
I am trying to load a web page content in a bho project
in DISPID_DOCUMENTCOMPLETE using the code below:
But I can not detect whether the page contains frame or not. Because
if(Doc->get_frames(&Frames)==S_OK)
return always S_OK whether the page contains frame or not.
So, I can not load web pages which doesn't contain any frame.
Any help will be highly appreciated!
Thanks in advance!
if(!pDispParams) return E_INVALIDARG;
CComQIPtr<IWebBrowser2, &IID_IWebBrowser2>m_spWebBrowser2Tmp;
m_spWebBrowser2Tmp = pDispParams->rgvarg[1].pdispVal;
if(m_spWebBrowser2Tmp) {
CComPtr<IDispatch> pIDispatch;
if (SUCCEEDED(m_spWebBrowser2Tmp->get_Document(&pIDispatch))) {
CComQIPtr<IHTMLDocument2,&IID_IHTMLDocument2> Doc;
pIDispatch->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&Doc);
if(Doc) {
TComInterface<IHTMLFramesCollection2> Frames;
if(Doc->get_frames(&Frames)==S_OK) {
long cnt = 0;
Frames->get_length(&cnt);
if (cnt>0) {
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 DocFrameStr = GetHTML(Doc2);
if(!DocFrameStr.IsEmpty()) {
// Do sth. with document
}
}
}
}
else {
// Never visited
}
}
}
}
AnsiString 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 "";
}
Technical Details
Message-ID:
<43c7e531$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: feeec,1c8ab6266d6ff57f,start X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Mehmet Caner" <mcaner40@hotmail.com> Newsgroups: borland.public.cppbuilder.internet.web Subject: Detecting whether a web site contains frame Date: Fri, 13 Jan 2006 19:38:35 +0200 Lines: 87 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 81.215.10.11 Message-ID: <43c7e531$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1137173809 81.215.10.11 (13 Jan 2006 09:36:49 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news3.google.com!newshub.sdsu.edu!peer01.west.cox.net!cox.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail