Solved

CppWebBrowser NewWindow2 Event [BCB5]

Posted on 2002-07-25
19
1,326 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

863 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

25 Experts available now in Live!

Get 1:1 Help Now