Solved

Getting URL address

Posted on 1998-06-18
8
217 Views
Last Modified: 2013-11-13
I made a Winsock program that can update me with what all the users in the Internet Lab are doing, but there are small problem, I can't get the current URL address of any user. all are using IE 3.02, I accessed the registry File, there are a key that store the Address of the current address .. but the problem is that it not updated automatically .. I have to close the IE until I get a final list of all the visited Site, can anybody HELP me to know how I can know what is the current URL in any Machine ?
Thanx alot
0
Comment
Question by:Anos
  • 5
  • 3
8 Comments
 
LVL 9

Expert Comment

by:Dalin
ID: 1463650
Anos,
Look like you want to get the current URL from the machine.
See if this is what you want: (assume you use NetScape and the caption start with "Netscape"
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: 1463651
Anos,
you should name form1 to frmWindowList or make changes in the code to match your window name
Regards
Dalin
0
 

Author Comment

by:Anos
ID: 1463652
Dalin,

       Thanx for what you did !! .. but it didn't work with me !!! .. nothing happened to me .. I did like what you said !! NOTHING !! .. anyway .. what I want is how I can get the Current URL from IE 3.02 !!
 
      I hope someOne can help me !!
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 9

Expert Comment

by:Dalin
ID: 1463653
Anos,
Sorry it did not work for you yet.
If you are using IE3.02, try to change the following code:

    ' See if the title ends with " - Netscape".
    If Left$(title, 8) = "Netscape" Then

to the caption of your internet Explaor, I believw it's Microsoft Inter..., adjust the size from 8 to the number of chars that distinguish your IE from other Apps, but stay constant.

My code works with Netscape, I tested. It should work for IE too, if you make the proper change. I will test the IE tomorrow and report back to you.

Regards
Dalin

0
 
LVL 9

Accepted Solution

by:
Dalin earned 200 total points
ID: 1463654
anos,
I tries with IE, it works. Any problems, let me know
Regards
Dalin
0
 

Author Comment

by:Anos
ID: 1463655
Thanx again Dalin !!

       Look I paste the code you gave me, and I run it .. and then I press the buttom there in the Form.. but nothing appeares in the Label !!! .. ALthogh there are no errors .. but it's not showing anything !! .. what should I do !! .. I opened the Netscape and then I run the program .. it that right !!?? .. plz tell me ..
0
 
LVL 9

Expert Comment

by:Dalin
ID: 1463656
Anos,
You should not accept an answer unless it works for you. Otherwise, you may get nothing for your points.

Yes, you have NetScape runing, and then run your project, click on the find button. It may take a little while.

If not work, try to place a break on the line "title = ..."
and then see the title every time it's there..
Make sure the Title in your Netscape   started with "Netscape", if not, change it in your program accordingly.

It works at my machine, and it worked for another questioner (click on my name you should see the two questions there)
Regards
Dalin

0
 

Author Comment

by:Anos
ID: 1463657
Dalin ... THAAAAAAAAAAAANX alot .. it works with me .. WooooW :-)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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…

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