🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.web
Article #461

Re: Help with TCppWebBrowser - Find and click a button

#461
From: mike
Date: Fri, 05 Jan 2007 22:48
132 lines
5064 bytes
Thank you Remy for responding to my question and problem.

I will study the code over the weekend and see if I can get this to work 
properly.

Mike

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:459ec5bf$1@newsgroups.borland.com...
>
> "mike" <mfbrowne@earthlink.nnet> wrote in message
> news:459ebec4$1@newsgroups.borland.com...
>
>> I would like to programmably be able to click a button on a web
>> page loaded into a TCppWebBrowser.
>
> You need to use the DOM intefaces for that.  If the button has a name,
> then you can use the IHTMLDocument2::all collection to find it
> quickly.  Otherwise, you have to drill down the parent/child hierarchy
> manually.  Either way, once you locate the button, you can obtain its
> IHTMLElement interface and then call its click() method.
>
>> The web page has a Tree View, I believe, on the left side and the
>> button is located within this view.
>
> There is no TreeView control in HTML.
>
>> If I view the source from within the browser the source looks like
> below:
>
> The only non-form button I see in that code is named "secure_exit".  I
> am assuming that the one you want.  The code to access it would look
> like this:
>
>    #include <mshtml.h>
>    #include <utilcls.h>
>
>    if( CppWebBrowser1->Document )
>    {
>        TComInterface<IHTMLDocument2> Doc;
>        CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
> (LPVOID*)&Doc);
>
>        if( Doc )
>        {
>            TComInterface<IHTMLElementCollection> All;
>            Doc->get_all(&All);
>
>            if( All )
>            {
>                TComInterface<IDispatch> Disp;
>                All->item(TVariant(WideString("secure_exit")),
> TVariant(0), &Disp);
>
>                if( Disp )
>                {
>                    TComInterface<IHTMLElement> Element;
>                    Disp->QueryInterface(IID_IHTMLElement,
> (LPVOID*)&Element);
>
>                    if( Element )
>                        Element->click();
>                }
>            }
>        }
>    }
>
>> This portion of the web page may also reside within a frame
>
> That makes a big difference.  You need the IHTMLDocument2 interface
> for the specific frame that you are going to search.  Starting with
> the top-level Document, you can use its frames collection to access
> the IHTMLWindow2 interface of each frame.  You can then use the
> IHTMLWindow2::document property to get the IHTMLDocument2 interface.
> For example:
>
>    #include <mshtml.h>
>    #include <utilcls.h>
>
>    if( CppWebBrowser1->Document )
>    {
>        TComInterface<IHTMLDocument2> Doc;
>        CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2,
> (LPVOID*)&Doc);
>
>        if( Doc )
>        {
>            TComInterface<IHTMLFramesCollection2> Frames;
>            Doc->get_frames(&Frames);
>
>            if( Frames )
>            {
>                TVariant IndexOrName = WideString("frame name");
>                // or:
>                // TVariant IndexOrName = SomeIndex;
>
>                TVariant Frame;
>                Frames->item(&IndexOrName, &Frame);
>
>                if( (V_VT(&Frame) == VT_DISPATCH) &&
> (V_DISPATCH(&Frame) != NULL) )
>                {
>                    TComInterface<IHTMLWindow2> Window;
>
> V_DISPATCH(&Frame)->QueryInterface(IID_IHTMLWindow2,
> (LPVOID*)&Window);
>
>                    if( Window )
>                    {
>                        TComInterface<IHTMLDocument2> FrameDoc;
>                        Window->get_document(&FrameDoc);
>
>                        if( FrameDoc )
>                        {
>                            // use FrameDoc as needed ...
>                        }
>                    }
>                }
>            }
>        }
>    }
>
> Refer to the following documentation for more information:
>
>    Interfaces and Scripting Objects
>
> http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/interface.asp
>
>
> Gambit
>
> 
Technical Details
Message-ID: <459ed5a5$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <459ebec4$1@newsgroups.borland.com> <459ec5bf$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,6ed59181280548e1
X-Google-Attributes: gidfeeec,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "mike" <mfbrowne@earthlink.nnet>
Newsgroups: borland.public.cppbuilder.internet.web
References: <459ebec4$1@newsgroups.borland.com> <459ec5bf$1@newsgroups.borland.com>
Subject: Re: Help with TCppWebBrowser - Find and click a button
Date: Fri, 5 Jan 2007 17:48:49 -0500
Lines: 134
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 68.207.98.36
Message-ID: <459ed5a5$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1168037285 68.207.98.36 (5 Jan 2007 14:48:05 -0800)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail