Solved

Read Webbrowser content having hwnd of the window

Posted on 2009-07-09
5
678 Views
Last Modified: 2012-05-07
When I search for the child windows I get:
"
ID: 0, ClassName: Static, Caption:
ID: 0, ClassName: Shell Embedding, Caption:
ID: 0, ClassName: Shell DocObject View, Caption:
ID: 0, ClassName: Internet Explorer_Server, Caption:
"

What I know is that there is a webbrowser withing the application. How can I have access to the application webbrowser content?

I have the hwnd of the application window. How do I go from here for getting the webbrowser content including the url it is taking the info from.

diandr
0
Comment
Question by:diandr
  • 3
5 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24818410
You don't need to use the handle, you can use the ShellWindows to check for the instance of IE you want to
get the doc from by using the code below.
uses ..., ShellAPI, ShDocvw, MSHTML;
 

var

  ShellWindow: IShellWindows;

  WB: IWebbrowser2;

  spDisp: IDispatch;

  IDoc1: IHTMLDocument2;

  k: Integer;

begin

  ShellWindow := CoShellWindows.Create;

  // get the running instance of Internet Explorer

  for k := 0 to ShellWindow.Count do

  begin

    spDisp := ShellWindow.Item(k);

    if spDisp = nil then Continue;

    // QueryInterface determines if an interface can be used with an object

    spDisp.QueryInterface(IWebbrowser2, WB);

    if WB <> nil then

    begin

      WB.Document.QueryInterface(IHTMLDocument2, iDoc1);

      // You now have the HTML document in the iDoc variable...

      if iDoc1.Title = 'Read Webbrowser content having hwnd of the window' then

      begin

        // This page matched the title that I wanted

      end;

    end;

  end;

end;

    

Open in new window

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 24827256
Well, that won't work for an application that just has an embedded webbrowser. Let me take a closer look.
0
 
LVL 3

Expert Comment

by:smot
ID: 24829141
1) Find the webbrowser handle by enumerating the child windows of that window
2) Retrieve IWebbrowser2 from it (search for GetIEFromHWND)
3) Get IHTMLDocument2 from it to access the wb source
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 500 total points
ID: 24830472
There is a Delphi implementation here: http://www.bsalsa.com/ie_tools_auto.html
0
 

Author Closing Comment

by:diandr
ID: 31601552
exactly what I wanted
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

861 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

29 Experts available now in Live!

Get 1:1 Help Now