CppWebBrowser NewWindow2 Event [BCB5]

What is LPDISPATCH *ppDisp used for and can I find out information i.e. size,toolbars visible,StatusBar visible etc.. on the opening window from it? Need examples.

What I need to know is how to cancel a new window from this event according to certain criteria to eliminate advertising popups. i.e size, sizeable ,and wether it has toolbars, scrollbars visible etc..

I don't want to eliminate new windows that where you shift/click on a link or window.new or "Open in new window"

 void __fastcall TMainForm::BrowserNewWindow2(TObject *Sender,
      LPDISPATCH *ppDisp, TOLEBOOL *Cancel)
{
if(PopBut->Down)
{
*Cancel=true;
}
}

Thanks
LVL 1
wolfpackincAsked:
Who is Participating?
 
AxterConnect With a Mentor Commented:
LPDISPATCH is a pointer to a IDispatch object.

IDispatch is a COM interface that is designed in such a way that it can call virtually any other COM interface.
0
 
AxterCommented:
0
 
AxterCommented:
Example:

void __fastcall TForm1::BrowserNewWindow2(TObject *Sender,
                                                    LPDISPATCH *ppDisp, TOLEBOOL *Cancel)
{
     TTabSheet *TabSheet = new TTabSheet(PageControl1);
     TabSheet->PageControl = PageControl1;
     TCppWebBrowser *WebBrowser = new TCppWebBrowser(TabSheet);
     WebBrowser->TOleControl::Parent = TabSheet;
     WebBrowser->Align = alClient;
     WebBrowser->OnNewWindow2 = BrowserNewWindow2;
     *ppDisp = WebBrowser->ControlInterface;
}
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
wolfpackincAuthor Commented:
>>IDispatch is a COM interface that is designed in such a way that it can call virtually any other COM interface.

Thats what I figured about IDispatch and have already read about it and don't understand it at all.I know nothing about COM.

Example:

>>void __fastcall TForm1::BrowserNewWindow2(TObject *Sender,
                                                   LPDISPATCH *ppDisp, TOLEBOOL *Cancel)
{
    TTabSheet *TabSheet = new TTabSheet(PageControl1);
    TabSheet->PageControl = PageControl1;
    TCppWebBrowser *WebBrowser = new TCppWebBrowser(TabSheet);
    WebBrowser->TOleControl::Parent = TabSheet;
    WebBrowser->Align = alClient;
    WebBrowser->OnNewWindow2 = BrowserNewWindow2;
    *ppDisp = WebBrowser->ControlInterface;
}

I can see where this would eliminate popups and instead use a page control? I'll try it.


0
 
wolfpackincAuthor Commented:
Yes the above works for tabs and I tryed also instead of tabs using ShellExcute() to execute nother instance of my browser program, but when I do that how do I pass or get the new URL to navigate to?

And is there a way to find out if its from a link on the html page or from window.new or open in new window?

or according to size, sizeable ,or wether it has toolbars, scrollbars visible etc..

for instance... popup adds usually dont't have scrollBars

thanks
0
 
AxterCommented:
>>but when I do that how do I pass or get the new URL to
>>navigate to?
I believe the following code will get you the url.
You should be able to add this to your

IHTMLDocument2 *iDoc2 = NULL;
TStringList *links = new TStringList;

if(SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
(LPVOID*)&iDoc2)))
{
    IHTMLElementCollection *iAnchors = NULL;
    if(SUCCEEDED(iDoc2->get_anchors(&iAnchors)))
    {
        long count = 0;
        if(SUCCEEDED(iAnchors->get_length(&count))
        {
            for(long x = 0; x < count; x++)
            {
                VARIANT idx;
                idx.vt = VT_I4;
                idx.lVal = x;

                VARIANT idx2;
                idx2.vt = VT_I4;
                idx2.lVal = 0;

                IDispatch *pItem = NULL
                iAnchors->get_Item(idx, idx2, &pItem);
                if(pItem != NULL)
                {
                    IHTMLAnchorElement *pAnchor = NULL;
                    if(SUCCEEDED(p->QueryInterface(IHTMLAnchorElement,
(LPVOID*)&pAnchor)))
                    {
                        BSTR bURL;
                        if(SUCCEEDED(pAnchor->get_href(&bURL)))
                            links->Add(WideString(bURL));
                        pAnchor->Release();
                    }
                    pItem->Release();
                }
            }
        }
        iAnchors->Release();
    } iDoc2->Release();
}

// use links, then...
delete links;
0
 
AxterCommented:
On your other questions, I'm sorry, but I can't help you too much there.
I'm more of a VC++ expert then Bordland.

There's already a free program available that can do the things your trying to do here.  And the source code is available for it, although I believe it's compiled in VC++.

I'll post a download link on my next post.
0
 
wolfpackincAuthor Commented:
Besides some other minor errors I've fixed in the code, I'm getting two other errors now and are marked in the comments below.

Otherwise I read up in the msdn library on all this and believe this is what I need. I understand it a little. I can't seem to find anything on IHtmlElementCollection->get_Item?

Have any Ideas?

header files added:
#include <unknwn.h>
#include <Mshtml.h>
#include <winerror.h>

IHTMLDocument2 *iDoc2 = NULL;
TStringList *links = new TStringList;

if(SUCCEEDED(Browser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&iDoc2)))
{
   IHTMLElementCollection *iAnchors = NULL;
   if(SUCCEEDED(iDoc2->get_anchors(&iAnchors)))
   {
       long count = 0;
       if(SUCCEEDED(iAnchors->get_length(&count)))
       {
           for(long x = 0; x < count; x++)
           {
               VARIANT idx;
               idx.vt = VT_I4;
               idx.lVal = x;

               VARIANT idx2;
               idx2.vt = VT_I4;
               idx2.lVal = 0;

               IDispatch *pItem = NULL;
               iAnchors->get_Item(idx, idx2, &pItem);  //Error get_Item not a member of IHtmlElementCollection
               if(pItem != NULL)
               {
                   IHTMLAnchorElement *pAnchor = NULL;
//if(SUCCEEDED(p->QueryInterface(IHTMLAnchorElement,
(LPVOID*)&pAnchor)))
//"Changed SUCCEEDED(p->" to SUCCEEDED(pItem->
                   if(SUCCEEDED(pItem->QueryInterface(IHTMLAnchorElement,(LPVOID*)&pAnchor)))//error: improper use of typedef IHTMLAnchorElement
                   {
                       BSTR bURL;
                       if(SUCCEEDED(pAnchor->get_href(&bURL)))
                           links->Add(WideString(bURL));
                       pAnchor->Release();
                   }
                   pItem->Release();
               }
           }
       }
       iAnchors->Release();
   } iDoc2->Release();
}

// use links, then... delete
 links->SaveToFile("links.txt");
 delete links;
0
 
wolfpackincAuthor Commented:
Besides some other minor errors I've fixed in the code, I'm getting two other errors now and are marked in the comments below.

Otherwise I read up in the msdn library on all this and believe this is what I need. I understand it a little. I can't seem to find anything on IHtmlElementCollection->get_Item?

Have any Ideas?

header files added:
#include <unknwn.h>
#include <Mshtml.h>
#include <winerror.h>

IHTMLDocument2 *iDoc2 = NULL;
TStringList *links = new TStringList;

if(SUCCEEDED(Browser->Document->QueryInterface(IID_IHTMLDocument2,(LPVOID*)&iDoc2)))
{
   IHTMLElementCollection *iAnchors = NULL;
   if(SUCCEEDED(iDoc2->get_anchors(&iAnchors)))
   {
       long count = 0;
       if(SUCCEEDED(iAnchors->get_length(&count)))
       {
           for(long x = 0; x < count; x++)
           {
               VARIANT idx;
               idx.vt = VT_I4;
               idx.lVal = x;

               VARIANT idx2;
               idx2.vt = VT_I4;
               idx2.lVal = 0;

               IDispatch *pItem = NULL;
               iAnchors->get_Item(idx, idx2, &pItem);  //Error get_Item not a member of IHtmlElementCollection
               if(pItem != NULL)
               {
                   IHTMLAnchorElement *pAnchor = NULL;
//if(SUCCEEDED(p->QueryInterface(IHTMLAnchorElement,
(LPVOID*)&pAnchor)))
//"Changed SUCCEEDED(p->" to SUCCEEDED(pItem->
                   if(SUCCEEDED(pItem->QueryInterface(IHTMLAnchorElement,(LPVOID*)&pAnchor)))//error: improper use of typedef IHTMLAnchorElement
                   {
                       BSTR bURL;
                       if(SUCCEEDED(pAnchor->get_href(&bURL)))
                           links->Add(WideString(bURL));
                       pAnchor->Release();
                   }
                   pItem->Release();
               }
           }
       }
       iAnchors->Release();
   } iDoc2->Release();
}

// use links, then... delete
 links->SaveToFile("links.txt");
 delete links;
0
 
wolfpackincAuthor Commented:
>> if(SUCCEEDED(pItem->QueryInterface(IHTMLAnchorElement,(LPVOID*)&pAnchor)))//error: improper use of typedef IHTMLAnchorElement

changed:
 if(SUCCEEDED(pItem->QueryInterface(IID_IHTMLAnchorElement,(LPVOID*)&pAnchor)))

is this right?I get no errors on this one anyway
0
 
wolfpackincAuthor Commented:
>> if(SUCCEEDED(pItem->QueryInterface(IHTMLAnchorElement,(LPVOID*)&pAnchor)))//error: improper use of typedef IHTMLAnchorElement

changed:
 if(SUCCEEDED(pItem->QueryInterface(IID_IHTMLAnchorElement,(LPVOID*)&pAnchor)))

is this right?I get no errors on this one anyway
0
 
wolfpackincAuthor Commented:
>> if(SUCCEEDED(pItem->QueryInterface(IHTMLAnchorElement,(LPVOID*)&pAnchor)))//error: improper use of typedef IHTMLAnchorElement

changed:
 if(SUCCEEDED(pItem->QueryInterface(IID_IHTMLAnchorElement,(LPVOID*)&pAnchor)))

is this right?I get no errors on this one anyway
0
 
AxterCommented:
Check out the following link:

http://www.codeproject.com/shell/surfhelper.asp

The program is free, and the source code is available on the same link.

I hate to see you reinvent the wheel.
0
 
AxterCommented:
>>f(SUCCEEDED(pItem->QueryInterface
>>(IID_IHTMLAnchorElement,(LPVOID*)&pAnchor)))

Sorry, but I can't say for certain.  Right now both my Bordland compiler and my VC compiler are both down.
0
 
wolfpackincAuthor Commented:
ok thanks will be back
0
 
wolfpackincAuthor Commented:
Okay thanks
0
 
JgouldCommented:
monitoring

JGould-EE Moderator
0
 
griesshCommented:
Dear

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "Axter"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
MindphaserCommented:
Force accepted

** Mindphaser - Community Support Moderator **
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.