Emily
02-15-2007, 08:56 PM
The API code at the bottom can show the last active URL in IE, Nestcape, ... (The first message box) BUT it cannot show Firefox's URL.
The IF statement works
Code:
If InStr(Title, "- Mozilla Firefox") Then
GetIEurl (Hwnd)
Any idea?
Thanks in advance
Emily
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetWindow Lib "user32" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowTextA Lib "user32" (ByVal Hwnd As Long, ByVal lpString _
As String, ByVal cch As Long) As Long
Declare Function SendMessageA Lib "user32" (ByVal Hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Declare Function GetClassNameA Lib "user32" (ByVal Hwnd As Long, ByVal lpClassName _
As String, ByVal nMaxCount As Long) As Long
Declare Function GetParent Lib "user32" (ByVal Hwnd As Long) As Long
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HE
Const GW_CHILD = 5
Const GW_HWNDNEXT = 2
Sub Main()
Dim Hwnd As Long
Dim Title As String
Dim TitleL As Integer
Hwnd = GetDesktopWindow
Hwnd = GetWindow(Hwnd, GW_CHILD)
Do While Hwnd <> 0
If GetParent(Hwnd) = 0 Then
Title = Space(256)
TitleL = GetWindowTextA(Hwnd, Title, 256)
Title = Left$(Title, TitleL)
If InStr(Title, "- Netscape") Or InStr(Title, "Tencent Traveler") Or _
InStr(Title, "TheWorld") Or InStr(Title, " - Microsoft Internet Explorer") Or _
InStr(Title, "- Mozilla Firefox") Then
GetIEurl (Hwnd)
End If
End If
Hwnd = GetWindow(Hwnd, GW_HWNDNEXT)
Loop
End Sub
Function GetClassName(Hwnd As Long) As String
Dim TempStr As String
Dim Rc As Long
TempStr = Space(260)
Rc = GetClassNameA(Hwnd, TempStr, Len(TempStr))
GetClassName = StrConv(LeftB$(StrConv(TempStr, vbFromUnicode), Rc), vbUnicode)
End Function
Function GetIEurl(H As Long) As String
Dim IeHwnd As Long
Dim cHwnd As Long
Dim UrlLen As Long
Dim IEurl As String
IeHwnd = GetWindow(H, GW_CHILD)
Do While IeHwnd <> 0
Debug.Print GetClassName(IeHwnd)
If GetClassName(IeHwnd) = "Edit" Then
UrlLen = SendMessageA(IeHwnd, WM_GETTEXTLENGTH, 0, 0)
If UrlLen <> 0 Then
UrlLen = UrlLen + 1
IEurl = Space$(UrlLen)
Call SendMessageA(IeHwnd, WM_GETTEXT, UrlLen, ByVal IEurl)
MsgBox Left$(IEurl, UrlLen)
Exit Do
End If
End If
cHwnd = GetWindow(H, GW_CHILD)
If cHwnd <> 0 Then GetIEurl IeHwnd
IeHwnd = GetWindow(IeHwnd, GW_HWNDNEXT)
Loop
End Function
Xtreme CrossPost on 10 Feb 07: http://www.xtremevbtalk.com/showthread.php?t=279452
The IF statement works
Code:
If InStr(Title, "- Mozilla Firefox") Then
GetIEurl (Hwnd)
Any idea?
Thanks in advance
Emily
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetWindow Lib "user32" (ByVal Hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowTextA Lib "user32" (ByVal Hwnd As Long, ByVal lpString _
As String, ByVal cch As Long) As Long
Declare Function SendMessageA Lib "user32" (ByVal Hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Declare Function GetClassNameA Lib "user32" (ByVal Hwnd As Long, ByVal lpClassName _
As String, ByVal nMaxCount As Long) As Long
Declare Function GetParent Lib "user32" (ByVal Hwnd As Long) As Long
Const WM_GETTEXT = &HD
Const WM_GETTEXTLENGTH = &HE
Const GW_CHILD = 5
Const GW_HWNDNEXT = 2
Sub Main()
Dim Hwnd As Long
Dim Title As String
Dim TitleL As Integer
Hwnd = GetDesktopWindow
Hwnd = GetWindow(Hwnd, GW_CHILD)
Do While Hwnd <> 0
If GetParent(Hwnd) = 0 Then
Title = Space(256)
TitleL = GetWindowTextA(Hwnd, Title, 256)
Title = Left$(Title, TitleL)
If InStr(Title, "- Netscape") Or InStr(Title, "Tencent Traveler") Or _
InStr(Title, "TheWorld") Or InStr(Title, " - Microsoft Internet Explorer") Or _
InStr(Title, "- Mozilla Firefox") Then
GetIEurl (Hwnd)
End If
End If
Hwnd = GetWindow(Hwnd, GW_HWNDNEXT)
Loop
End Sub
Function GetClassName(Hwnd As Long) As String
Dim TempStr As String
Dim Rc As Long
TempStr = Space(260)
Rc = GetClassNameA(Hwnd, TempStr, Len(TempStr))
GetClassName = StrConv(LeftB$(StrConv(TempStr, vbFromUnicode), Rc), vbUnicode)
End Function
Function GetIEurl(H As Long) As String
Dim IeHwnd As Long
Dim cHwnd As Long
Dim UrlLen As Long
Dim IEurl As String
IeHwnd = GetWindow(H, GW_CHILD)
Do While IeHwnd <> 0
Debug.Print GetClassName(IeHwnd)
If GetClassName(IeHwnd) = "Edit" Then
UrlLen = SendMessageA(IeHwnd, WM_GETTEXTLENGTH, 0, 0)
If UrlLen <> 0 Then
UrlLen = UrlLen + 1
IEurl = Space$(UrlLen)
Call SendMessageA(IeHwnd, WM_GETTEXT, UrlLen, ByVal IEurl)
MsgBox Left$(IEurl, UrlLen)
Exit Do
End If
End If
cHwnd = GetWindow(H, GW_CHILD)
If cHwnd <> 0 Then GetIEurl IeHwnd
IeHwnd = GetWindow(IeHwnd, GW_HWNDNEXT)
Loop
End Function
Xtreme CrossPost on 10 Feb 07: http://www.xtremevbtalk.com/showthread.php?t=279452