Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getobject - how to get children windows of returned InternetExplorer

Status
Not open for further replies.

JL42

Technical User
Jun 23, 2003
12
US
I have tried the following code with internet explorer opened, and one of the links opened in a new window.

set oie1 = getobject( ,"InternetExplorer.Application")
set oie2 = getobject( ,"InternetExplorer.Application")
'set a breakpoint on the next statement
junk = "garbage"

it returns the top level iexplore.exe for both of them.
I'm trying to find a way to grab hold of that second window.
I've browsed the objects with view->locals and cant seem to find the child window collection.
 
Try this. It will only work properly if there are only two IE windows open. If there can possibly be move than two you will have to figure out how to identify the one you want based on the properties of tmpWindow.
Code:
Private Sub Command1_Click()
On Error GoTo ErrorHandler

  Dim oie1 As SHDocVw.InternetExplorer
  Set oie1 = GetObject(, "InternetExplorer.Application")
  
  Dim oie2 As SHDocVw.InternetExplorer
  Set oie2 = getBrowserChildWindow(oie1)
  
  If oie2 Is Nothing Then
    MsgBox "Browser child window not found.", vbExclamation
  End If
  
  Exit Sub
  
ErrorHandler:

  MsgBox Err.Description, vbExclamation
  
  Set oie1 = Nothing
  Set oie2 = Nothing

End Sub

Private Function getBrowserChildWindow(ByVal ie1 As InternetExplorer) As InternetExplorer
On Error GoTo ErrorHandler

  Dim windowList As SHDocVw.ShellWindows
  Set windowList = New SHDocVw.ShellWindows
  
  Dim windowIdx As Long
  For windowIdx = 0 To windowList.Count - 1
    
    Dim tmpWindow As SHDocVw.InternetExplorer
    
    On Error Resume Next
    Set tmpWindow = windowList.Item(windowIdx)
    
    If Err.Number = 0 Then
    
      If ie1.FullName = tmpWindow.FullName And _
       ie1.hwnd <> tmpWindow.hwnd Then
      
        Set getBrowserChildWindow = tmpWindow
        Exit For
        
      End If
    Else
      Err.Clear
    End If
  
  Next windowIdx
  
  Set tmpWindow = Nothing
  
  Exit Function

ErrorHandler:

  Set tmpWindow = Nothing
  Set getBrowserChildWindow = Nothing
  
  Err.Raise Err.Number, Err.Source, Err.Description

End Function

“I apologize for this long letter. I didn't have the time to make it any shorter” --Blaise Pascal
 
Thanks, that's the key I was looking for, the shellwindows collection. (curious, why it returns only IE object windows and not webbrowser object windows, or all windows? Oh well another time)

In fact, I have boiled it down to a small demo in VBScript that gives back the URL of each open window.
=============================================
dim objShell, objShellWindows, i

set objShell = createObject(&quot;Shell.Application&quot;)
set objShellWindows = objShell.Windows

if (not objShellWindows is nothing) then
for i = 0 to objShellWindows.count - 1
msgbox objShellWindows.Item(i).locationurl
next
end if

'thanks to member billchris
=============================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top