🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.web
3 messages
3 total messages Started by Mehmet Caner Fri, 13 Jan 2006 17:38
Detecting whether a web site contains frame
#860
Author: Mehmet Caner
Date: Fri, 13 Jan 2006 17:38
84 lines
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 "";
}
Re: Detecting whether a web site contains frame
#861
Author: Remy Lebeau (TeamB)
Date: Fri, 13 Jan 2006 18:01
24 lines
1833 bytes
"Mehmet Caner" <mcaner40@hotmail.com> wrote in message
news:43c7e531$1@newsgroups.borland.com...

> But I can not detect whether the page contains frame or not.

That is because you are not taking into account that the
DISPID_DOCUMENTCOMPLETE event is triggered separately for each individual
frame.  Your code is assuming that when the event is triggered, it is only
triggered for the top-level document that contains the frames inside of it.
That is not always the case.  When the event is triggered for a particular
frame, your code is then checking if that document has frames of its own.
If it does not, then you code is ignoring the frame that triggered the
event.

> if(Doc->get_frames(&Frames)==S_OK)
>
> return always S_OK whether the page contains frame or not.

As it should be.  The return value indicates whether the collection itself
was retreived.  Not whether the collection was filled with anything.


Gambit
Re: Detecting whether a web site contains frame
#863
Author: Mehmet Caner
Date: Fri, 13 Jan 2006 22:17
8 lines
1243 bytes
Hi Remy,

Thank you very much not only for your kind answer,
but also valuable code, that takes me this point, in the archive.

I got what I need.

Mehmet
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