Solved

"Internet Explorer_Server" to WebBrowser control

Posted on 2001-09-17
4
442 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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