|
-
Jun 1st, 2001, 02:26 AM
#1
Thread Starter
Hyperactive Member
Browser handle
Dear all,
Is it possible to get the browser's window handle. thanks in advance.
-
Jun 4th, 2001, 01:50 PM
#2
New Member
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.
-
Jun 7th, 2001, 11:02 PM
#3
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|