Solved

"Internet Explorer_Server" to WebBrowser control

Posted on 2001-09-17
4
479 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

630 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