Results 1 to 3 of 3

Thread: Browser handle

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    266

    Browser handle

    Dear all,
    Is it possible to get the browser's window handle. thanks in advance.

  2. #2
    New Member
    Join Date
    May 2001
    Location
    Midwest, USA
    Posts
    3
    Sure,

    Do you know what the caption of the Window will be? If so, use the following..

    NOTE: REPLACE >> GO.com - Microsoft Internet Explorer << with the caption of the window you want to locate.

    ' Declare necessary API routines:
    Private Declare Function FindWindow Lib "user32" Alias _
    "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long


    Private Declare Function SendMessage Lib "user32" Alias _
    "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long


    Function DetectIE() As Long
    ' Procedure dectects a running IE
    Const WM_USER = 1024
    Dim hwnd As Long
    ' If IE is running this API call returns its handle.
    hwnd = FindWindow("IEFRAME", "GO.com - Microsoft Internet Explorer")

    If hwnd = 0 Then ' 0 means IE not running.
    MsgBox ("No IE")
    DetectIE = 0
    Exit Function
    Else
    ' IE is running so use the SendMessage API
    ' function to enter it in the Running Object Table.
    SendMessage hwnd, WM_USER + 18, 0, 0
    MsgBox ("IE hwnd = " & hwnd)
    DetectIE = hwnd

    End If
    End Function


    The Following is a TEST click I used in an Access DB

    Private Sub Command0_Click()
    On Error GoTo Err_Command0_Click

    Dim MyIE As Object ' Variable to hold reference
    ' to Microsoft IE.
    Dim IEWasNotRunning As Boolean ' Flag for final release.

    On Error Resume Next ' Defer error trapping.

    Set MyIE = GetObject(, "IEFRAME")
    If err.Number <> 0 Then IEWasNotRunning = True
    err.Clear ' Clear Err object in case error occurred.

    nWnd = DetectIE()




    ' Close
    If IEWasNotRunning = True Then
    MyIE.Application.Quit
    End If

    Set MyIE = Nothing ' Release reference to the


    Exit_Command0_Click:
    Exit Sub

    Err_Command0_Click:
    MsgBox err.Description
    Resume Exit_Command0_Click

    End Sub


    Mike S.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    266
    Thanks mschoenrock

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width