Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get the IE Window Object from handle (IE.HWND)?

40 views
Skip to first unread message

Chris Young

unread,
Nov 1, 2001, 7:12:10 PM11/1/01
to
Apologies for this rather Newbie question...How can I get the Window *Object*
if I have the Window Handle? I am automating Internet Explorer from Visual
Basic, and I want to know when the user switches IE windows (assuming multiple
IE windows are up, e.g., a pop-up). I need to catch events (esp OnFocus) from
the IE Window.

I was thinking something simple like:
===========================
Dim WithEvents IE As InternetExplorer
Dim WithEvents IEWin As ???????
.
.
.
Set IE = CreateObject("InternetExplorer.Application")
Set IEWin = SomeFuncToGetTheWindowObject(IE.HWND)

And then:

Private Sub IEWin_OnFocus()

<Code to handle focus change here>

============================

Thoughts?

Thanks,
Chris

Garcia Francois

unread,
Nov 29, 2001, 4:46:31 AM11/29/01
to
To get events from InternetExplorer window, subscribe to WebBrowser
events and then to HTMLWindow2 events when you receive a "navigate
complete" notification :

--- Sample begin --------------------------------------

Dim ie As New SHDocVw.InternetExplorer
Dim win As IHTMLWindow2
Dim WithEvents ieEvt As SHDocVw.WebBrowser
Dim WithEvents winEvt As HTMLWindow2

Private Sub Form_Load()
Set ieEvt = ie
ie.Visible = True
ie.Navigate "http://hongkong.scmp.com/index.html"
End Sub

Private Sub ieEvt_NavigateComplete2(ByVal pDisp As Object, URL As
Variant)
' Called when navigation is completed
' Get document window and subscribe on its events
Dim wb As WebBrowser
Set wb = pDisp
Set win = wb.Document.parentWindow
Set winEvt = win
End Sub

Private Sub winEvt_OnFocus()
' Called when window has focus
End Sub

Private Sub winEvt_OnBlur()
' Called when window lost focus
End Sub

--- Sample end --------------------------------------


FG.


cb...@home.com (Chris Young) wrote in message news:<9rsn5q$mg...@kcweb01.netnews.att.com>...

0 new messages