|
-
Mar 27th, 2000, 12:29 PM
#1
Thread Starter
New Member
I've spent several hours today trying to figure this out, but I just can't get it. What I want to be able to do is get the current address (and page title if possible) from IE and throw it in a listbox on my form.
Thanks in advance!
-
Mar 27th, 2000, 10:14 PM
#2
Sure. But you would have to use APIs. Here's whow to get the current URL and a Page Title:
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) 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 Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As String) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD
Private Sub Command1_Click()
Dim lngIE As Long
Dim lngWrkArea As Long
Dim lngEditBox As Long
Dim strEditText As String
Dim lngEditLen As Long
Dim lngCaptionLen As Long
Dim strCaption As String
lngIE = FindWindowEx(0, 0, "IEFrame", vbNullString)
lngWrkArea = FindWindowEx(lngIE, 0, "WorkerW", vbNullString)
lngWrkArea = FindWindowEx(lngWrkArea, 0, "ReBarWindow32", vbNullString)
lngWrkArea = FindWindowEx(lngWrkArea, 0, "ComboBoxEx32", vbNullString)
lngWrkArea = FindWindowEx(lngWrkArea, 0, "ComboBox", vbNullString)
lngEditBox = FindWindowEx(lngWrkArea, 0, "Edit", vbNullString)
lngEditLen = SendMessage(lngEditBox, WM_GETTEXTLENGTH, 0, 0)
strEditText = Space(lngEditLen)
If SendMessageStr(lngEditBox, WM_GETTEXT, lngEditLen, ByVal strEditText) Then
strEditText = Left(strEditText, InStr(strEditText, vbNullChar) - 1)
End If
lngCaptionLen = GetWindowTextLength(lngIE)
strCaption = Space(lngCaptionLen + 1)
If GetWindowText(lngIE, strCaption, lngCaptionLen + 1) Then
strCaption = Left(strCaption, InStr(strCaption, "- Microsoft Internet Explorer") - 1)
End If
MsgBox "The current URL: " & strEditText & vbCrLf & _
"Page Title: " & strCaption
End Sub
Also, you can add a reference to Microsoft Internet Controls (shdocvw.dll) to control the IE the way you want it.
-
Mar 27th, 2000, 11:30 PM
#3
Thread Starter
New Member
You're great Serge! Thanks so much. Originally, I was trying to use SendMessages with CB_GETLBTEXT and that did nothing.
The only thing: I had to change "WorkerW" to "WorkerA" because that's what I found in Spy++. Are there other possibilities on different systems with different versions of IE?
-
Mar 27th, 2000, 11:35 PM
#4
Thread Starter
New Member
It should also be noted, I had to change all instances of lngEditLen to lngEditLen + 1.
lngEditLen = SendMessage(lngEditBox, WM_GETTEXTLENGTH, 0, 0)
strEditText = Space(lngEditLen + 1)
If SendMessageStr(lngEditBox, WM_GETTEXT, lngEditLen + 1, ByVal strEditText) Then
strEditText = Left(strEditText, InStr(strEditText, vbNullChar))
End If
Otherwise, it works like a charm!
-
Aug 20th, 2000, 08:12 PM
#5
Frenzied Member
I'm confused, it seems to work for everybody except for me 
It does display the Title but not the URL, and unfortunatly that's the only thing i need can anyone please help?
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Aug 20th, 2000, 08:39 PM
#6
Look at this thread which gwdash has answered. He shows how to get the url from IE. I tried the code and it does work.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|