Solved

Getting URL address

Posted on 1998-06-18
8
212 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now