|
Thread: QQ
-
Sep 26th, 2000, 10:39 AM
#1
Thread Starter
Lively Member
Want to know how to grab a website address from the address bar in ie explorer and return that information to my program.
-
Sep 26th, 2000, 11:54 AM
#2
Guru
I wrote this one a long time ago, and I really don't feel like editing it now, so ignore any bad coding standards or dumb code, etc. 
Just copying and pasting really old code, ok?
And here it is:
Code:
Option Explicit
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWndParent As Long, ByVal hWndSearchAfter As Long, ByVal lpClassName As String, ByVal lpWindowName 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 Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD
Private Enum KnownInternetBrowserTypes
NetscapeNavigator
InternetExplorer
End Enum
Function GetTextBoxText(ByVal hWndTextBox As Long) As String
Dim sLine() As Byte
ReDim sLine(0 To SendMessage(hWndTextBox, WM_GETTEXTLENGTH, 0, ByVal vbNullString))
If UBound(sLine) = 0 Then Exit Function
sLine(0) = UBound(sLine) And 255
sLine(1) = UBound(sLine) \ 256
Call SendMessage(hWndTextBox, WM_GETTEXT, UBound(sLine) + 1, sLine(0))
GetTextBoxText = Left(StrConv(sLine, vbUnicode), UBound(sLine))
End Function
Function IsNetscapeHandle(ByVal hWndUnsure As Long) As Boolean
If hWndUnsure = 0 Then Exit Function
hWndUnsure = FindWindowEx(hWndUnsure, 0, "msctls_statusbar32", vbNullString)
If hWndUnsure = 0 Then Exit Function
hWndUnsure = FindWindowEx(hWndUnsure, 0, vbNullString, "Netscape Task Bar")
If hWndUnsure = 0 Then Exit Function
IsNetscapeHandle = True
End Function
Function FindNetscape(Optional ByVal hWndSearchAfter As Long = 0, Optional ByRef hWndParent As Long) As Long
Dim hWndOriginal As Long
FindNetscape = hWndSearchAfter
Do
FindNetscape = FindWindowEx(0, FindNetscape, vbNullString, vbNullString)
If FindNetscape = 0 Then Exit Function
Loop Until IsNetscapeHandle(FindNetscape)
hWndParent = FindNetscape
FindNetscape = FindWindowEx(FindNetscape, 0, vbNullString, vbNullString)
FindNetscape = FindWindowEx(hWndParent, FindNetscape, vbNullString, vbNullString)
hWndOriginal = FindNetscape
FindNetscape = FindWindowEx(FindNetscape, 0, vbNullString, vbNullString)
FindNetscape = FindWindowEx(hWndOriginal, FindNetscape, vbNullString, vbNullString)
FindNetscape = FindWindowEx(FindNetscape, 0, vbNullString, vbNullString)
FindNetscape = FindWindowEx(FindNetscape, 0, "ComboBox", vbNullString)
FindNetscape = FindWindowEx(FindNetscape, 0, "Edit", vbNullString)
End Function
Function FindExplorer(ByVal WindowType As Long, Optional ByVal hWndSearchAfter As Long = 0, Optional ByRef hWndParent As Long) As Long
FindExplorer = FindWindowEx(0, hWndSearchAfter, IIf(WindowType = 0, "IEFrame", "CabinetWClass"), vbNullString)
If FindExplorer = 0 Then Exit Function
hWndParent = FindExplorer
FindExplorer = FindWindowEx(FindExplorer, 0, "WorkerA", vbNullString)
FindExplorer = FindWindowEx(FindExplorer, 0, "ReBarWindow32", vbNullString)
FindExplorer = FindWindowEx(FindExplorer, 0, "ComboBoxEx32", vbNullString)
FindExplorer = FindWindowEx(FindExplorer, 0, "ComboBox", vbNullString)
FindExplorer = FindWindowEx(FindExplorer, 0, "Edit", vbNullString)
End Function
Private Sub AddURLsToListBox(lstBox As ListBox, ByVal BrowserType As KnownInternetBrowserTypes)
Dim hWndSearch As Long, sURL As String, hWndParent As Long
Call lstBox.Clear
Do
sURL = GetTextBoxText(hWndSearch)
If Trim(sURL) <> vbNullString Then Call lstBox.AddItem(Trim(sURL))
If BrowserType = InternetExplorer Then hWndSearch = FindExplorer(0, hWndParent, hWndParent)
If BrowserType = NetscapeNavigator Then hWndSearch = FindNetscape(hWndParent, hWndParent)
Loop Until hWndSearch = 0
hWndParent = 0
If BrowserType = InternetExplorer Then
Do
sURL = GetTextBoxText(hWndSearch)
If Trim(sURL) <> vbNullString Then Call lstBox.AddItem(Trim(sURL))
hWndSearch = FindExplorer(1, hWndParent, hWndParent)
Loop Until hWndSearch = 0
End If
End Sub
And here's how to use it:
Code:
' The following will retrieve URLs from all open Internet Explorer windows,
' and throw them into a ListBox called lstExplorer.
Call AddURLsToListBox(lstExplorer, InternetExplorer)
' The following will do the same, but with open Netscape windows,
' and into a ListBox called lstNetscape.
Call AddURLsToListBox(lstNetscape, NetscapeNavigator)
Enjoy!
-
Sep 28th, 2000, 11:00 AM
#3
Thread Starter
Lively Member
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
|