🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3662

Re: API to detect which URL is open in Internet Explorer

#3662
From: gizmo
Date: Fri, 12 May 2006 19:07
116 lines
4625 bytes
"Thorsten Meyer" <meyer.t@hhb.bonn.de> wrote:
>Hi
>how it is possible in Builder 5 to connect to am IE Browser window with a
>DOM interface, i don't find any way to implement such an interface. Does
>anyone know a link to code examples or Tutorials who explain this technique

If I it is correct has understood...

//in hpp
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//TComInterface
#include <utilcls.h>
// ShellWindows
#include <exdisp.h>
// MSHTML
#include <mshtml.h>
// Dispatch IDS for IExplorer Dispatch Events
#include <exdispid.h>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
    TButton *Button1;
    TListBox *ListBox1;
    void __fastcall Button1Click(TObject *Sender);
    
private:	// User declarations
    TComInterface<IShellWindows> pSW;
public:		// User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

//cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    CoInitialize(NULL);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    if(pSW.CreateInstance(__uuidof(ShellWindows)) == S_OK)
    {
        ListBox1->Clear();

        // get windows
        LONG nCount;
        pSW->get_Count( &nCount);

        for (int i=0; i<nCount; i++)
        {
            // get next window
            TComInterface<IDispatch> pDisp;
            pSW->Item( TVariant(i), &pDisp);
            TComInterface<IWebBrowser2> pIE;
            pDisp->QueryInterface(IID_IWebBrowser2, (LPVOID*)&pIE);
            if (pIE)
            {
                // get URL
                WideString wsUrl;
                pIE->get_LocationURL( &wsUrl);

                // trying to get htmldoc
                TComInterface<IDispatch> pDispDoc;
                pIE->get_Document( &pDispDoc);
                TComInterface<IHTMLDocument2> pHtmlDoc;
                pDispDoc->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pHtmlDoc);

                // if Ok, - Internet Explorer'�
                if (pHtmlDoc)
                {
                    //see it work...
                    //pHtmlDoc->put_bgColor( CComVariant( L"blue"));
                    IWebBrowser2* pBrowser = pIE;
                    pBrowser->AddRef();
                    ListBox1->Items->AddObject(String("Internet Explorer: ") + wsUrl, (TObject*)pBrowser);
                    // connect events
                    //...
                }
                // else - Explorer
                else
                {
                    //ListBox1->Items->Add(String("Window Explorer: ") + wsUrl);
                    // Close Window
                    //pIE->Quit();
                }
            }
        }
    }
    else ShowMessage("Shell Windows interface is not avilable");
}
Technical Details
Message-ID: <4464dcf3$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <44465d36@newsgroups.borland.com> <4446769f$1@newsgroups.borland.com> <4447509e@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,49a04f82ae43f13c
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII
From: "gizmo" <_gizmo@mail.ru>
Sender: "gizmo" <_gizmo@mail.ru>
Reply-To: "gizmo" <_gizmo@mail.ru>
Subject: Re: API to detect which URL is open in Internet Explorer
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 195.201.33.13     
X-Forwarded-For: unknown
References: <44465d36@newsgroups.borland.com> <4446769f$1@newsgroups.borland.com> <4447509e@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <4464dcf3$1@newsgroups.borland.com>
Date: 12 May 2006 12:07:31 -0700
X-Trace: newsgroups.borland.com 1147460851 207.105.83.66 (12 May 2006 12:07:31 -0700)
Lines: 116
Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail