Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Determining top most Internet Explorer window. (top most)

Posted on 2004-11-04
4
Medium Priority
?
267 Views
Last Modified: 2008-02-20
Hi,
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.

Thanks!
0
Comment
Question by:flosoft
  • 2
4 Comments
 
LVL 9

Expert Comment

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

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21164345.html

Hope it helps answer your question as well.
0
 

Author Comment

by:flosoft
ID: 12495548
Wow,
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.

Thanks
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 12496167
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
    Next

End Sub
0
 

Author Comment

by:flosoft
ID: 12496235
Sweet, Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question