Is that possible to detect runngin URL ?

let say, I have either IE or Netscape running. And can I
use vb program to detect the URL ?

How ?
LVL 1
tanc02Asked:
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.

roysterCommented:
Yes it is.
make a project with a module and a form1 then put in below code as directed.

Put this in module:
'Go to URL
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

'Find URL in browser
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 contains browser name
If InStr(title, "Internet Explorer") Or InStr(title, "Netscape") Then
' This is it. Find the ComboBox information.
Form1.txtURL = EditInfo(app_hwnd) '***change to form your using

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


'End Find URL -----------------------------------------


put this in form 1's load event

'Function for finding current URL in browser
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, ByVal lParam As Long) As Long

Private Sub Form_Load()
EnumWindows AddressOf EnumProc, 0
txtURL.SelStart = Len(txtURL)

'use below line to open browser and go to the url
'nResult = ShellExecute(Form1.hwnd, "open", txtURL, "", "", 5)
End Sub
0

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
roysterCommented:
oops... put a textbox on form1 called txtURL also
0
tanc02Author Commented:
excellent !
0
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.