Solved

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

Posted on 2004-08-16
8
1,282 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Expert Comment

by:adg080898
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 3

Accepted Solution

by:
Belthazor earned 500 total points
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:Stimphy
Comment Utility
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
Comment Utility
My Spy++ shows the class of the client area is "Internet Explorer_Server" and the title blank.
0
 
LVL 3

Expert Comment

by:Belthazor
Comment Utility
@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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

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

11 Experts available now in Live!

Get 1:1 Help Now