handle

Hi

If we have a few internet explorers open how do we obtain a reference to each internet explorer running in vb6 to handle each window separately

thanks
RichardsAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
' ------------------------------
'  Form1
' ------------------------------

' Project --> References --> Check "Microsoft Scripting Runtime"

Option Explicit

Private Sub Command1_Click()
    Set IE = New Dictionary
    EnumWindows AddressOf EnumWindowsProc, ByVal 0&
   
    Dim key As Variant
    For Each key In IE.Keys
        Debug.Print key, IE.Item(key)
    Next
End Sub


' ------------------------------
'  Module1
' ------------------------------
Option Explicit

Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpclassname As String, ByVal nMaxCount As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public IE As Dictionary

Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
    Dim sName As String
    Dim lRet As Long

    If IE Is Nothing Then
        Set IE = New Dictionary
    End If
   
    sName = Space(256)
    lRet = GetClassName(hWnd, sName, Len(sName))
    sName = UCase(Left(sName, lRet))
    If sName = "IEFRAME" Then
        IE.Add CStr(hWnd), GetWindowCaption(hWnd)
    End If
   
    EnumWindowsProc = True
End Function

Public Function GetWindowCaption(ByVal windowHandle As Long) As String
    GetWindowCaption = String(GetWindowTextLength(windowHandle) + 1, Chr$(0))
    GetWindowText windowHandle, GetWindowCaption, Len(GetWindowCaption)
End Function
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
 
RichardsAuthor Commented:
Thanks ! Can you help me make it more specific to mine . I need to print each memo and handle value of all the IE's opened
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What do you mean by "memo"?
0
 
RichardsAuthor Commented:
Thanks  ! the name on each explore for this link on IE it is showing Visual Basic: handle.Question 21810969 - ....

0
 
RichardsAuthor Commented:
I mean the name for each IE link
0
 
EDDYKTCommented:
may be this?

Option Explicit
Private Declare Function GetWindow Lib "USER32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetParent Lib "USER32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowText Lib "USER32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowPos Lib "USER32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Declare Function ShowWindow Lib "USER32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long


Private Sub Command1_Click()
findWindowRunning "MICROSOFT INTERNET EXPLORER"

End Sub
Public Sub findWindowRunning(taskName As String)
    Dim titleTmp As String
    Dim nRet As Long, hWndTmp As Long
   
    On Error Resume Next

    ' Find First window and loop throug master window list
    hWndTmp = FindWindow(vbNullString, vbNullString)

    Do Until hWndTmp = 0
        ' make sure this window has no parent
        Err.Clear
        If GetParent(hWndTmp) = 0& Then

            ' Retrieve caption text from current window
            titleTmp = Space(256)
            nRet = GetWindowText(hWndTmp, titleTmp, Len(titleTmp))

            If nRet Then
                'Clean up return string preparing for case-insensitive comparision
                titleTmp = UCase(Left(titleTmp, nRet))
                If (InStr(titleTmp, taskName) <> 0) Then  ' Partial
                    Dim title As String
               
                    title = Right(titleTmp, nRet - Len(taskName))
                    title = LTrim(title)
                    title = RTrim(title)
                    Debug.Print title
                End If
            End If
        End If
       
        ' Get next window in master list and continue
        hWndTmp = GetWindow(hWndTmp, 2)
    Loop
End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.