Solved

CppWebBrowser NewWindow2 Event [BCB5]

Posted on 2002-07-25
19
1,324 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:wolfpackinc
19 Comments
 
LVL 30

Accepted Solution

by:
Axter earned 300 total points
ID: 7178182
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
 
LVL 30

Expert Comment

by:Axter
ID: 7178188
0
 
LVL 30

Expert Comment

by:Axter
ID: 7178210
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
 
LVL 1

Author Comment

by:wolfpackinc
ID: 7178303
>>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
 
LVL 1

Author Comment

by:wolfpackinc
ID: 7180914
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
 
LVL 30

Expert Comment

by:Axter
ID: 7181019
>>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
 
LVL 30

Expert Comment

by:Axter
ID: 7181042
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
 
LVL 1

Author Comment

by:wolfpackinc
ID: 7181372
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
 
LVL 1

Author Comment

by:wolfpackinc
ID: 7181478
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Author Comment

by:wolfpackinc
ID: 7181483
>> 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
 
LVL 1

Author Comment

by:wolfpackinc
ID: 7181532
>> 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
 
LVL 1

Author Comment

by:wolfpackinc
ID: 7181571
>> 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
 
LVL 30

Expert Comment

by:Axter
ID: 7182095
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
 
LVL 30

Expert Comment

by:Axter
ID: 7182098
>>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
 
LVL 1

Author Comment

by:wolfpackinc
ID: 7182103
ok thanks will be back
0
 
LVL 1

Author Comment

by:wolfpackinc
ID: 7182125
Okay thanks
0
 

Expert Comment

by:Jgould
ID: 7230291
monitoring

JGould-EE Moderator
0
 
LVL 11

Expert Comment

by:griessh
ID: 7439559
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
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7479719
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now