Solved

How can I get the handle to the client part of IE

Posted on 2004-08-16
8
1,289 Views
Last Modified: 2008-01-09
Hi all,

Looking for a way that from a program I can (a) open an instance of IE and (b) get the handle to the "client part" of that open IE web browser.  The client part is the area in which the web page is rendered.

Would like to understand how to do this in either VB.NET or C#.NET.

Can anyone help ?

Thanks,

John
0
Comment
Question by:trzesniakj
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Expert Comment

by:adg080898
ID: 11815551
Hmm. Don't know VB that well, but you could do something like this:

x = CreateObject("InternetExplorer.Application")

x.document.body = "<html><head>From VB</head><body>Hello VB COM world</body></html>"

messagebox "Click OK to close"

Does that work?
0
 

Author Comment

by:trzesniakj
ID: 11817398
No.  But thank you for taking time to respons.

I'm looking to get the actual window "handle" (unique window identifier in the OS for each window and control created...and it's an integer) to the part of the browser that renders the web page for something else I need to do.

Thanks,

John
0
 
LVL 3

Expert Comment

by:Belthazor
ID: 11817567
Hi,
all you ned is the Windows Caption and an API Function:

---------------------------------------------------------------------------------------------
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal pszClass As String, ByVal lpszWindow As String) As Long

Dim IEWindowHandle As Long, IECaption as String
IEWindowHandle  = 0
IECaption = "Google - Microsoft Internet Explorer" 'Must be exact

IEWindowHandle = FindWindowEx(IEWindowHandle , 0, vbNullString, IECaption)
If IEWindowHandle = 0 Then
   'Error handling
Else
   'You found the Handle, saved in IEWindowHandle
End If
---------------------------------------------------------------------------------------------
and by the way .... a windows handle has always 'Long' datatype

good luck
Belthazor

0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 3

Accepted Solution

by:
Belthazor earned 500 total points
ID: 11817630
Hi,
in case you need some sample code how to get the client area: you can just use FindWindowEx again:

Dim ClientArea as Long
ClientArea = 0

 'You found the Handle, saved in IEWindowHandle
FindWindowEx(IEWindowHandle, 0, "Shell DocObject View", "")

Explanations:
This is the declaration of FindWindowEx:

FindWindowEx(HWND hwndParent, HWND hwndChildAfter, LPCTSTR lpszClass, LPCTSTR lpszWindow)

hwndParent: the IEWindowHandle we found above
hwndChildAfter: search all Windows within the IE Dialog
lpszClass: The class of the Windows, as you see above it is "Shell DocObject View". You can find out things like this using the Spy++ tool of Microsoft, which is includid in Visual Studio 6. (If you dont have it, download "spyxx.exe", "spyhk55.dll" and "spyxx.hlp" from http://www.et.utt.ro/public/ProgLangs/VisualStudio6/common/tools/ )
lpszWindow: Window's Caption. According to Spy++ the Caption of the Client Area is ""

Hope you'll get it to work
Belthazor
0
 
LVL 3

Expert Comment

by:Stimphy
ID: 11817921
Try This:

Reference Microsoft Internet Controls

Dim IE As InternetExplorer
Set IE = New InternetExplorer
IE.Navigate2 "www.google.com"
IE.Visible = True
MsgBox IE.hWnd

Here is are some links to microsoft that may be useful.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;238313
http://www.microsoft.com/mind/0898/dom.asp

Regaurds,
Dave
0
 
LVL 8

Expert Comment

by:adg080898
ID: 11818056
My Spy++ shows the class of the client area is "Internet Explorer_Server" and the title blank.
0
 
LVL 3

Expert Comment

by:Belthazor
ID: 11818066
@adq: Mine too, as Child of "Shell DocObject View"
@John: Depending on what you are planning to do: trial and error with the classes
0
 

Author Comment

by:trzesniakj
ID: 11824734
Thank you all so much.  I have to play with it a little bit.  But I think I can take it from here !

Thanks,

John
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Simple Linear Regression

623 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