> An ugly hack would be to send the Firefox window the F6 shortcut (selects
> text in address bar) and copy it to the clipboard
Hehe, I've been doing that for years, but with CTRL+L to select the Address
Bar, to avoid the F6 bug that netmaestro mentions. I never posted my tip
here because I was ashamed of having to do it that way.

But here it is.
@netmaestro: Again, I swear I did not copy your code. We just think alike!
And also, you should check for both "http://" and "https://", for secure sites.
Code: Select all
Procedure.s GetFirefoxURL()
ff=FindWindow_("MozillaUIWindowClass",0)
If ff
SetForegroundWindow_(ff)
keybd_event_(#VK_CONTROL,0,0,0) ; Hold down Control key.
keybd_event_(#VK_L,0,0,0) : keybd_event_(#VK_L,0,#KEYEVENTF_KEYUP,0) ; Go to Address Bar.
keybd_event_(#VK_C,0,0,0) : keybd_event_(#VK_C,0,#KEYEVENTF_KEYUP,0) ; Copy the address.
keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0) ; Release Control key.
Sleep_(125) : u$=GetClipboardText() ; Delay seems to be needed here.
EndIf
ProcedureReturn u$
EndProcedure
Debug GetFirefoxURL()
Further, here's some Visual Basic code that I once found that supposedly
does it... maybe someone here can convert it to PureBasic?
Code: Select all
I got to playing around with the Active Accessibility
approach. I don't know whether this is really a usable
solution, but it's interesting. This is VB6 code. I guess
it's about the same for VB5.
This code would need some adjustments for your
purpose, but this shows it can be done, at least.
As for AA, it's in Windows at least as far back as
Win98, but I'm not certain that it's always installed
by default.
----------------------------------------------
Set the following code if a form named "F1":
Private Sub bHook_Click()
Hook
End Sub
Private Sub bUnhook_Click()
UnHook
End Sub
Place 2 buttons, as named above, with captions "hook" and
"unhook".
Place a textbox named "Text1"
-----------------------------------
In a module add this code (Reference to Accessibility needed in
Project -> References. Lib. is oleacc.dll. Set "Show hidden
Objects" in object browser if you want intellisense.)
Public Const EVENT_MIN = 1&
Private Const ROLE_COMBOBOX = &H2E&
Private Const OB_ACCELERATORCHANGE = &H8012&
Private Const SYS_ALERT = 2&
Public Const WINEVENT_SKIPOWNPROCESS = 2&
Public Const OB_REORDER = &H8004&
Private Declare Function SetWinEventHook Lib "user32.dll" (ByVal eventMin As
Long, ByVal eventMax As Long, ByVal hmodWinEventProc As Long, ByVal
pfnWinEventProc As Long, ByVal idProcess As Long, ByVal idThread As Long,
ByVal dwFlags As Long) As Long
Private Declare Function UnhookWinEvent Lib "user32.dll" (ByVal lHandle As
Long) As Long
Private Declare Function AccessibleObjectFromEvent Lib "oleacc" (ByVal HWnd
As Long, ByVal dwId As Long, ByVal dwChildId As Long, ppacc As IAccessible,
pvarChild As Variant) As Long
Private LHook As Long
Public Sub Hook()
Dim LRet As Long
LHook = SetWinEventHook(SYS_ALERT, OB_ACCELERATORCHANGE, 0&, AddressOf
WinEventFunc, 0, 0, WINEVENT_SKIPOWNPROCESS)
End Sub
Public Sub UnHook()
Dim LRet As Long
If LHook = 0 Then Exit Sub
LRet = UnhookWinEvent(LHook)
End Sub
Public Function WinEventFunc(ByVal HookHandle As Long, ByVal LEvent As Long,
ByVal HWnd As Long, ByVal idObject As Long, ByVal idChild As Long, ByVal
idEventThread As Long, ByVal dwmsEventTime As Long) As Long
Dim ObA As IAccessible
Dim LRet As Long
Dim V As Variant
Dim s As String, s1 As String, sName As String
On Error Resume Next
Select Case LEvent
Case OB_REORDER
LRet = AccessibleObjectFromEvent(HWnd, idObject, idChild, ObA, V)
If LRet = 0 Then
F1.Text1.Text = "--"
If CLng(ObA.accRole(V)) = 46 Then '-- combobox.
If ObA.accName(V) = "Location" Then
F1.Text1.Text = ObA.accValue(V)
End If
End If
End If
End Select
WinEventFunc = 0
End Function
-------------------------------
Open Firefox, run the project, click "Hook".
Edit the Firefox location bar.
You should see the text in Text1 keep up
with any changes you make in Firefox's
location bar.