vb controling the topmost instance of IE
if anyone here has had the same headache I have had I am posting this for you. I have a program that controls IE with events the only problem with this you cannot have an array with events so my users were limited to using only the single instance of IE. If they opened a new window it was no use so here is my code to control the instance of IE with focus...
VB Code:
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Public WithEvents IE As SHDocVw.InternetExplorer
Private Sub Timer1_Timer()
Dim strTitle As String
Dim lngRet As Long
lngRet = GetForegroundWindow() ' Get the handle of the foreground window.
On Error Resume Next
If (lngRet <> IE.hwnd) Then
Set objShell = New Shell
For Each obj In objShell.Windows
If TypeName(obj.Document) = "HTMLDocument" Then
If obj.hwnd = lngRet Then
Set IE = obj
End If
End If
Next obj
End If
End Sub
Re: vb controling the topmost instance of IE