Solved

"Internet Explorer_Server" to WebBrowser control

Posted on 2001-09-17
4
452 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
ID: 6744237
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
ID: 6744490
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
ID: 6744983
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
ID: 6752603
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

679 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