Solved

"Internet Explorer_Server" to WebBrowser control

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Define unique primary key 9 99
no14 challenge 14 76
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 134
Notepad++ Question 11 26
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 …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

734 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