Solved

Read Webbrowser content having hwnd of the window

Posted on 2009-07-09
5
682 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

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

685 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