Solved

"Internet Explorer_Server" to WebBrowser control

Posted on 2001-09-17
4
431 Views
Last Modified: 2013-11-20
How do you retrieve a handle of an input control on a webpage from another application? I have the handle of the
"Internet Explorer_Server" control and now I need to retrieve a handle of a input box on a text drag/drop operation so I can fill in the text. I have been able to
retrieve the html content from this application, but how do I get the HWND handle?

0
Comment
Question by:dcorb
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
There is no HWND for controls on a web page.  Verify this by using Spy++

In order to place data into a webpage control, the best method is to open that page in a webbrowser control, walk the DOM to locate the control, then set its value.  If that solution will work for you, let me know and i'll take a crack at coding it up.

-- Dan
0
 

Author Comment

by:dcorb
Comment Utility
Hi Dan

I have been attempting to walk the the DOM but I only got
as far as retrieving the HTML code. I have not been to get down the input control elements yet. A code example would be great.

Dave
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 300 total points
Comment Utility
There are two parts to this question.  First, I'm not certain, but I think that you want to hook into a running instance of Internet Explorer.  If that is an absolute requirement, then you are probably out of luck.  There seems to be a way to do it with IE 4 and there is a way to do it with IE 5+ if there are some additional 'accessibility' componemts installed on the computer and some other prerequisites.  And there is another, very complicated, method that involves creating an IE helper DLL.

But perhaps at the end of the day, all you *really* want to do is open a web page and automatically fill-in one or more input fields on a web page.  That can be complicated, but it really boils down to a very few lines of code.

For test purposes, I created a dialog-based app and added a Microsoft WebBrowser ActiveX control to the dialog.  I  used the Class Wizard to create a variable for it (named it m_ctlBrowser).  I then used the ClassWizard to create a handler for the OnDocumentComplete event and used this code:

// note: uncomment the top line and compile once.
// Then comment out the top line and uncomment the second line
//#import "c:\winnt\system32\mshtml.tlb"
#include "debug\mshtml.tlh"

void CD07WebDlg::OnDocumentCompleteExplorer2(LPDISPATCH pDisp, VARIANT FAR* URL)
{
     MSHTML::IHTMLDocument2Ptr pDoc( m_ctlBrowser.GetDocument() );

     MSHTML::IHTMLElementCollectionPtr pCollAll= pDoc->Getall();

     MSHTML::IHTMLInputElementPtr pInputText=  pCollAll->item("addr");
     bstr_t bstrValue= pInputText->Getvalue();

     pInputText->value="1234 Main Streeeet";
}

All this does is get a pointer to the dispatch for the HTML DOM, then get access to the 'all' list of elements, then get a pointer to a text input element whose name is 'addr'.  It then sets that element's value to a literal string.  Note that it must be done after the document is fully loaded into the control, thus this code belongs in the OnDocumentComplete handler.

I found out the name 'addr' by examining the source file at the target web page (in IE, open the page, right-click, and select View Source)

=--=-==-=-=-=-=-=-=-=-=-
I made a button on the dialog and connected this code to its command so that it would open and display the page:

void CD07WebDlg::OnButton1()
{
     m_ctlBrowser.Navigate("http://maps.yahoo.com", 0,0,0,0 );
}

=-=-=-=-=-
So, now you can insert values into an input field on a web page.  How 'bout that!

-- Dan
0
 

Author Comment

by:dcorb
Comment Utility
I did manage to connect to a running instance of IE and access the input controls. I am developing with IE6 and still have to test with previous versions of IE.

Thank you for your help.

Dave
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

743 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

11 Experts available now in Live!

Get 1:1 Help Now