Page 2 of 5
Posted: Wed Dec 20, 2006 1:07 pm
by rsts
Not too shabby, especially coming from someone who says "I love nothing better than an ugly hack. . ."
This is beautiful. I just might have to remove that 'ugly hack' it took so long to perfect.
And it's great for me that it only retrieves the url on an active window, 'cause that's the only time I really care about it, and it might be the only one sending keyboard events.
cheers
Posted: Wed Dec 20, 2006 1:57 pm
by Sparkie
Well son-of-a-b.... my original code worked fine at home, but here at work it's a no go like the rest of you. I can't believe how much difference there is between my home PC and my work PC. I can't remember the last time I produced code that worked correctly on both machines.
Thanks for your input netmaestro, and don't be shy about adding your name to the credits.

Posted: Wed Dec 20, 2006 3:11 pm
by rsts
Does anyone know if the presence of the hook would cause the program to be flagged as malware?
cheers
Posted: Wed Dec 20, 2006 4:00 pm
by rsts
It's always something.
using firefox with tabs. 5 or 6 tabs open. I switch a tab - it shows me the new one. great.
except
If one of the tabs is welcome to gmail (waiting to login, not already logged in), it is always returned whether it's the active tab or not. there may be others that exhibit this same behavior.
So now, how to determine which tab is really the active one - the one the user is actually using?
I'm starting to hate firefox
cheers
Posted: Wed Dec 20, 2006 10:30 pm
by rsts
Adding the focus check seems to make it perform as I need it.
Once again, I owe you guys. This forum is incredible.
Code: Select all
;************************************************
; Code: Track Firefox url changes (no IE / Opera support as of yet)
; Author: Sparkie/netmaestro
; Date: December 21, 2006
; OS: Windows only
;...Code converted from VB to PB
;...Thanks To PB for posting the original VB code
;...Code is not yet perfect so feel free to clean
;...it up and use as you wish.
; ************************************************
;
; *** IMPORTANT *** This approach requires an editorgadget on your window
;
;############
; Constants
;############
#WINEVENT_OUTOFCONTEXT = 0
#WINEVENT_SKIPOWNPROCESS = $2
#CHILDID_SELF = 0
#ROLE_COMBOBOX = $2E
#EVENT_OBJECT_VALUECHANGE = $800E
;############
; Hook proc
;############
Procedure WinEventFunc(HookHandle.l, LEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l)
Static oldurl$
Protected oba.IAccessible
If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @oba, @v.VARIANT) = #S_OK
v\vt = #VT_I4
v\lVal = 0
r = oba\get_accRole(v, @v)
v\vt = #VT_I4
v\lVal = 0
Asc$ = Space(#MAX_PATH)
Uni$ = Space(#MAX_PATH*2+2)
MultiByteToWideChar_(#CP_ACP, 0, @Asc$, -1, @Uni$, Len(Asc$)*2+2)
bstr = SysAllocString_(@Uni$)
If oba\get_accfocus( @v)=#S_FALSE ; added this to eliminate GMail auto focus
ProcedureReturn
EndIf
If oba\get_accValue(v, @bstr) = #S_OK
len = WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, 0, 0, 0, 0)
url$ = Space(len)
WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, @url$, len, 0, 0)
If Left(url$,4) = "http"
If url$<>oldurl$
oldurl$ = url$
AddGadgetItem(1, -1, url$)
EndIf
EndIf
EndIf
SysFreeString_(bstr)
EndIf
EndProcedure
;############
; Main Window
;############
If OpenWindow(0, 0, 0, 500, 400, "Read FireFox URL", #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
hdll = OpenLibrary(0, "Oleacc.dll")
EditorGadget(1, 10, 15, 480, 380)
;...Set event hook
eHook = SetWinEventHook_(1, #MAXWORD, #Null, @WinEventFunc(), 0, 0, #WINEVENT_OUTOFCONTEXT | #WINEVENT_SKIPOWNPROCESS)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
;...Cleanup in isle 53
If eHook
UnhookWinEvent_(eHook)
EndIf
If hdll
CloseLibrary(0)
EndIf
EndIf
End
cheers
Posted: Thu Dec 21, 2006 4:13 am
by Sparkie
PB wrote:BTW, does anyone know why this doesn't work if the EditorGadget is removed?
Hmmm...works fine for me here with or without the EditorGadget...which means when I get to my PC at work in the morning, it won't work there.
I've been testing this with Opera and no luck. Seems Opera does not fully support MSAA.
netmaestro wrote:OK, main problem is too much filtering.
I have to disagree with you on that. On my current version of this code, I am hooking $8005 thru $800A. IMHO, hooking from 1 thru #MAXWORD is overkill, unless of course that's the only way you can get it to function properly

Posted: Thu Dec 21, 2006 5:55 am
by rsts
Sparkie wrote:PB wrote:BTW, does anyone know why this doesn't work if the EditorGadget is removed?
Hmmm...works fine for me here with or without the EditorGadget...which means when I get to my PC at work in the morning, it won't work there.
I've been testing this with Opera and no luck. Seems Opera does not fully support MSAA.
netmaestro wrote:OK, main problem is too much filtering.
I have to disagree with you on that. On my current version of this code, I am hooking $8005 thru $800A. IMHO, hooking from 1 thru #MAXWORD is overkill, unless of course that's the only way you can get it to function properly

Hmm - could be part of the problem - in the 'published' version you were only hooking valuechange - not statechange thru valuechange.
Might make a difference - or as netmaestro said 'too much filtering'
I agree with you though - I am going to cut back some. i also seem to be getting memory errors when I close a window, so i have to figure out how to do some error checking
cheers
Posted: Thu Dec 21, 2006 9:47 am
by PB
> works fine for me here with or without the EditorGadget...which means
> when I get to my PC at work in the morning, it won't work there.
I see you're using XP Home; what version does your work have? I have Pro.
Posted: Thu Dec 21, 2006 1:54 pm
by Sparkie
Both home and work PC's have WinXP Home, and both have PB 4.01.
The original code I posted works fine for me at home, but not at work. No biggie as my new code works fine on both.
(If I ever find a reason for this oddity, I'll let you know.)
Posted: Thu Dec 21, 2006 3:56 pm
by rsts
Sparkie wrote:
No biggie as my new code works fine on both.
Please?
cheers
Posted: Thu Dec 21, 2006 6:33 pm
by Sparkie
Sure thing rsts. I am at work right now so I will post the code later tonight after I get home.

Posted: Thu Dec 21, 2006 11:36 pm
by netmaestro
overkill
Agreed, its really more a place to start and work back from, stopping when the range is reasonable and still working everywhere. Sounds like you're pretty much there, Sparkie!

Posted: Fri Dec 22, 2006 1:58 am
by Sparkie
Here's my current code. As of now, I don't see a way to catch Opera URL's using MSAA, but I will continue searching for a different method.
rsts, let me know how this works with your GMail thingy so I/we can make any necessary adjustments. I haven't tested with IE7 tabbed browsing so you are on your own there for now.
Code: Select all
; ************************************************
; Code : Read Browser URL (IE, Firefox)
; Author(s) : Sparkie, netmaestro
; Other credits : PB, rsts
; Date : December 21, 2006 7:41 PM
; Target OS : Windows only
; Target PB : 4.x
;...Code converted from VB to PB
;...Feel free to clean it up and use as you wish.
; ************************************************
;############
; Constants
;############
#CHILDID_SELF = 0
#WINEVENT_OUTOFCONTEXT = 0
#WINEVENT_SKIPOWNPROCESS = $2
#EVENT_OBJECT_FOCUS = $8005
#EVENT_OBJECT_STATECHANGE = $800A
#ROLE_SYSTEM_CLIENT = $A
#ROLE_DOCUMENT = $F
#ROLE_SYSTEM_PANE = $10
;############
; Hook proc
;############
Procedure WinEventFunc(HookHandle.l, LEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l)
Protected *objectIa.IAccessible
Static previousUrl$
Select LEvent
Case #EVENT_OBJECT_FOCUS, #EVENT_OBJECT_STATECHANGE
className$ = Space(256)
GetClassName_(hwnd, @className$, 256)
If className$ = "OperaWindowClass"
AddGadgetItem(1, -1, "OperaWindowClass")
EndIf
If className$ = "MozillaWindowClass" Or className$ = "Internet Explorer_Server"
If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @*objectIa, @v.VARIANT) = #S_OK
v.VARIANT\vt = #VT_I4
v\lVal = 0
If *objectIa\get_accRole(v, @v) = #S_OK
If v\lVal = #ROLE_SYSTEM_PANE Or v\lVal = #ROLE_DOCUMENT
v\vt = #VT_I4
v\lVal = 0
Asc$ = Space(#MAX_PATH)
Uni$ = Space(#MAX_PATH*2+2)
MultiByteToWideChar_(#CP_ACP, 0, @Asc$, -1, @Uni$, Len(Asc$)*2+2)
bstr = SysAllocString_(@Uni$)
If *objectIa\get_accValue(v, @bstr) = #S_OK
len = WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, 0, 0, 0, 0)
url$ = Space(len)
WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, @url$, len, 0, 0)
If previousUrl$ <> url$
AddGadgetItem(1, -1, className$ + ": " + url$)
previousUrl$ = url$
EndIf
EndIf
SysFreeString_(bstr)
EndIf
*objectIa\Release()
EndIf
EndIf
EndIf
EndSelect
EndProcedure
;############
; Main Window
;############
If OpenWindow(0, 0, 0, 500, 400, "Read Browser URL", #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
hdll = OpenLibrary(0, "Oleacc.dll")
EditorGadget(1, 10, 15, 480, 380)
;...Set event hook
eHook = SetWinEventHook_(#EVENT_OBJECT_FOCUS, #EVENT_OBJECT_STATECHANGE, #Null, @WinEventFunc(), 0, 0, #WINEVENT_OUTOFCONTEXT | #WINEVENT_SKIPOWNPROCESS)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
;...Cleanup in isle 78
If eHook
UnhookWinEvent_(eHook)
EndIf
If hdll
CloseLibrary(0)
EndIf
EndIf
End
Posted: Fri Dec 22, 2006 3:38 am
by rsts
Looks to me as if you've done it again!
Works perfectly for me. Doesn't show the Gmail login screen as always in focus. It has better screening than what I had put together to eliminate the abend upon closing a browser window. Works for both ie and FF, which I had previously used seperate routines to accomplish.
No downside at all so far, so I'm off to tesing other portions of the program.
Between you and netmaestro, I just may get something running fairly decently.
Thanks to you both - and PB for posting the vb code. I had seen it in a couple of forums (as a response to 'learner'), but was too intimidated by it to try anything with it.
Kind of redundant but - thanks once again.
cheers
hmm - ie7 tabbed browsing? Guess i better take a look at that

Posted: Fri Dec 22, 2006 8:34 am
by PB
> I had seen it in a couple of forums (as a response to 'learner')
