Solved

Read Webbrowser content having hwnd of the window

Posted on 2009-07-09
5
677 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
There is a Delphi implementation here: http://www.bsalsa.com/ie_tools_auto.html
0
 

Author Closing Comment

by:diandr
Comment Utility
exactly what I wanted
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

772 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

12 Experts available now in Live!

Get 1:1 Help Now