Solved

Read Webbrowser content having hwnd of the window

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

809 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