Determining top most Internet Explorer window. (top most)

having a little trouble with this one.

I created an ie toolbutton app, from which I need to get the URL of the browser that launched my app from.

Here is the form startup code I have so far...

Dim SWs As New SHDocVw.ShellWindows
Dim tmpIE As SHDocVw.InternetExplorer
  For Each tmpIE In SWs
  txtURL.Text = tmpIE.LocationURL
End If

this works ok, but if they have more than one broswer open, I get the url from the browser that
navigated last, I need to get the URL from the browser they launched my app from, or what should be the current top most IE window. I have looked into functions to determine this, but they are all C++ examples which is foriegn to me.

Also my app runs as topmost, however I could set this after I have pulled the URL if I have to.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shahid ThaikaSole ProprietorCommented:
I have answered a similar question recently. Though it still hasn't been answered as yet, I am sure it is a good answer.

Hope it helps answer your question as well.
flosoftAuthor Commented:
there is alot there. Guess I was hoping someone had written an easy function I could call
from the above code, something like

Dim SWs As New SHDocVw.ShellWindows
Dim tmpIE As SHDocVw.InternetExplorer
  For Each tmpIE In SWs
if IsTopMost(tmpIE) then
  txtURL.Text = tmpIE.LocationURL
End if
End If

I will look through that page some more but it will take some time to sort out what portions I would need and would not because there is alot more there than I need.

Give this a try...

Option Explicit

Private Declare Function GetForegroundWindow Lib "user32" () As Long

Sub Command1_Click()

    Dim shWnds As New ShellWindows
    Dim ie As InternetExplorer
    Dim lhWnd As Long
    Dim sURL As String
    sURL = ""
    'Loop all the instances of IE and see if one has focus
    For Each ie In shWnds
        'Get the handle of the window with focus
        lhWnd = GetForegroundWindow()
        'See if any IE windows have the focus
        If (ie.hWnd = lhWnd) Then
            '---===### This one has focus ###===---
            sURL = ie.LocationURL
        End If

End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
flosoftAuthor Commented:
Sweet, Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.