?
Solved

Getting URL from an open browser

Posted on 1998-06-19
6
Medium Priority
?
208 Views
Last Modified: 2010-05-03
I want to be able to get  a url (and maybe say the last 10 visited) from an open browser.. if no browser is open, then maybe just the last 10 visited.. is there any EASY way to do this?
0
Comment
Question by:sonix061998
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Dalin
ID: 1463808
sonix,
I have a way to get the current one. You can have it running and add it to a list.
However, it does not do anything if the browser is not open.
If you like, I will post that.
Regards
Dalin
0
 
LVL 1

Expert Comment

by:johnny_5
ID: 1463809
Well, that all depends on what browser now.... :)


0
 

Author Comment

by:sonix061998
ID: 1463810
Dalin,
  yes that would be EXCELLENT.  Thanks!

0
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!

 

Author Comment

by:sonix061998
ID: 1463811
Dalin,
  yes that would be EXCELLENT.  Thanks!

0
 
LVL 9

Accepted Solution

by:
Dalin earned 400 total points
ID: 1463812
Sonix,
Here you are. See if this works for you(it assume you use NetScape and the caption start with "Netscape", you can adjust)
Regards
Dalin

    Copy these code to a module:

    Option Explicit

    Public Type ProcData
        AppHwnd As Long
        title As String
        Placement As String
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type

    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As
    Long) As Long

    Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As
    Long
    Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal
    nMaxCount As Long) As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As
    Long, lParam As Any) As Long

    Private Const WM_GETTEXT = &HD
    Private Const WM_GETTEXTLENGTH = &HE

    Private Const GW_CHILD = 5
    Private Const GW_HWNDNEXT = 2
    Private Const GW_HWNDFIRST = 0
    ' ***********************************************
    ' If this window is of the Edit class, return
    ' its contents. Otherwise search its children
    ' for an Edit object.
    ' ***********************************************
    Public Function EditInfo(window_hwnd As Long) As String
    Dim txt As String
    Dim buf As String
    Dim buflen As Long
    Dim child_hwnd As Long
    Dim children() As Long
    Dim num_children As Integer
    Dim i As Integer

        ' Get the class name.
        buflen = 256
        buf = Space$(buflen - 1)
        buflen = GetClassName(window_hwnd, buf, buflen)
        buf = Left$(buf, buflen)
         
        ' See if we found an Edit object.
        If buf = "Edit" Then
            EditInfo = WindowText(window_hwnd)
            Exit Function
        End If
         
        ' It's not an Edit object. Search the children.
        ' Make a list of the child windows.
        num_children = 0
        child_hwnd = GetWindow(window_hwnd, GW_CHILD)
        Do While child_hwnd <> 0
            num_children = num_children + 1
            ReDim Preserve children(1 To num_children)
            children(num_children) = child_hwnd
             
            child_hwnd = GetWindow(child_hwnd, GW_HWNDNEXT)
        Loop
         
        ' Get information on the child windows.
        For i = 1 To num_children
            txt = EditInfo(children(i))
            If txt <> "" Then Exit For
        Next i

        EditInfo = txt
    End Function
    ' ************************************************
    ' Return the text associated with the window.
    ' ************************************************
    Public Function WindowText(window_hwnd As Long) As String
    Dim txtlen As Long
    Dim txt As String

        WindowText = "" 
        If window_hwnd = 0 Then Exit Function
         
        txtlen = SendMessage(window_hwnd, WM_GETTEXTLENGTH, 0, 0)
        If txtlen = 0 Then Exit Function
         
        txtlen = txtlen + 1
        txt = Space$(txtlen)
        txtlen = SendMessage(window_hwnd, WM_GETTEXT, txtlen, ByVal txt)
        WindowText = Left$(txt, txtlen)
    End Function


    Public Function EnumProc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean
    Dim buf As String * 1024
    Dim title As String
    Dim length As Long

        ' Get the window's title.
        length = GetWindowText(app_hwnd, buf, Len(buf))
        title = Left$(buf, length)

        ' See if the title ends with " - Netscape".
        If Left$(title, 8) = "Netscape" Then
            ' This is it. Find the ComboBox information.
            frmWindowList.lblAddress = EditInfo(app_hwnd)

            ' Stop searching.
            EnumProc = 0
        Else
            ' Continue searching til find it.
            EnumProc = 1
        End If
    End Function

    in form1, drop a label name it lblAddress, and a command button name it cmdFindAddress,
    add code:

    Option Explicit

    Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal lParam As Long) As Long
    ' Start the enumeration.

    Private Sub cmdFindAddress_Click()
        lblAddress.Caption = "" 
        EnumWindows AddressOf EnumProc, 0
    End Sub
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1463813
sonix,
you should name form1 to frmWindowList or make changes in the code to match your window name
Regards
Dalin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

840 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