Solved

CppWebBrowser NewWindow2 Event [BCB5]

Posted on 2002-07-25
19
1,332 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

830 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