Page 3 of 5

Posted: Sat May 10, 2008 4:57 am
by jogwang2
is there any c# to this code. it would really be helpful.

Posted: Sat Jul 19, 2008 9:23 am
by BigJack
Pretty good piece of code - thanks for sharing it.

Is there a way to do it without opening a window? :?:
Greetings Mike

Posted: Wed Jul 23, 2008 6:37 am
by Little John
On SourceForge there is a project called URLInject. Unfortunately it is abandoned, but the source code (Pascal) might be interesting for you guys anyway.

Regards, Little John

Posted: Wed Jul 23, 2008 2:43 pm
by PB
@Sparkie: Your excellent code no longer works with the new Firefox 3. :(
Any chance you can revisit it soon and make it both 2 and 3 compatible? ;)
Or even just for Firefox 3 would be great. Thanks, and I hope you can do it.

Posted: Wed Jul 23, 2008 5:19 pm
by Sparkie
BigJack and PB, I'll take a look when I get home tonight. :)

Posted: Thu Jul 24, 2008 3:07 am
by Sparkie
As for the Firefox 3 issue, I'm not sure what's going wrong. get_accName (which is the Title of the page) is working fine but get_accValue (the url of the page) is stumbling for some reason. I will continue to look for a fix.

Posted: Thu Jul 24, 2008 5:11 am
by PB
Just to confirm: you're using the normal Firefox 3, and not Firefox Portable or
any other non-official derivative of it?

Posted: Thu Jul 24, 2008 12:41 pm
by Sparkie
That is correct PB
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1

Posted: Sat Jul 26, 2008 3:54 pm
by Sparkie
See if this works for you and Firefox 3...

Code: Select all

; Code          : Read Browser URL (IE, Firefox) 
; Author(s)     : Sparkie, netmaestro 
; Other credits : PB, rsts 
; Rel Date      : December 21, 2006 7:41 PM 
; Update        : July 26, 2008 10:49 AM
;                 -fix for Firefox 3
; 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_VALUECHANGE = $800E
#ROLE_SYSTEM_DOCUMENT = $F
#ROLE_SYSTEM_PANE = $10
#ROLE_SYSTEM_TEXT = $2A

;################
; Convert to BSTR
;################
; Thanks to freak for this one
Procedure.l ASCIItoBSTR(asciiString$)
  Protected result = 0
  CompilerIf #PB_Compiler_Unicode
  result = SysAllocString_(@asciiString$)
  CompilerElse
  Protected *buff = AllocateMemory(Len(asciiString$)*2 + 2)
  If *buff
    PokeS(*buff, asciiString$, -1, #PB_Unicode)
    result = SysAllocString_(*buff)
    FreeMemory(*buff)
  EndIf
  CompilerEndIf
  ProcedureReturn result
EndProcedure 

;################
; Set Hook
;################
Procedure WinEventFunc(HookHandle.l, hEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l) 
  Protected *objectIa.IAccessible 
  Static previousUrl$ 
  Select hEvent 
    Case #EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE
      className$ = Space(256) 
      GetClassName_(hwnd, @className$, 256) 
      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 = #CHILDID_SELF 
          If *objectIa\get_accRole(v, @v) = #S_OK 
            If v\lVal = #ROLE_SYSTEM_PANE Or v\lVal = #ROLE_SYSTEM_DOCUMENT Or v\lVal = #ROLE_SYSTEM_TEXT
              v\vt = #VT_I4 
              v\lVal = #CHILDID_SELF 
              url$ = Space(#MAX_PATH) 
              bstr = ASCIItoBSTR(Space(#MAX_PATH))
              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$ And url$ <> ""
                  AddGadgetItem(1, -1, url$) 
                  previousUrl$ = url$ 
                EndIf 
              EndIf 
            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)) 
  CoInitialize_(0);
  hdll = OpenLibrary(0, "Oleacc.dll") 
  EditorGadget(1, 10, 15, 480, 380) 
  ;...Set event hook 
  eHook = SetWinEventHook_(#EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE, #Null, @WinEventFunc(), 0, 0, #WINEVENT_OUTOFCONTEXT | #WINEVENT_SKIPOWNPROCESS) 
  Repeat 
    event = WaitWindowEvent() 
  Until event = #PB_Event_CloseWindow 
  ;...Cleanup
  CoUninitialize_()
  If eHook 
    UnhookWinEvent_(eHook) 
  EndIf 
  If hdll 
    CloseLibrary(0) 
  EndIf 
EndIf 
End

Posted: Sun Jul 27, 2008 2:13 am
by PB
> See if this works for you and Firefox 3

Hi Sparkie, it seems to work great so far, so thanks for that! :)

One caveat: if Firefox is running BEFORE you run your code, then it doesn't get
the current URL. In the big scheme of things that won't matter to me because
my app is launched at bootup before Firefox, but if you can make it get the
URL of an already-running Firefox, then it would be 100% perfect. :)

Posted: Sun Jul 27, 2008 1:22 pm
by Sparkie
Your request should be no problem PB. I'll get on it later today. :)

Posted: Sun Jul 27, 2008 8:28 pm
by Pantcho!!
Sparkie, damn you are good! :lol:

Posted: Sat Aug 02, 2008 8:18 am
by PB
@Sparkie: I was looking closer at your code and saw this:

*value = AllocateMemory(#MAX_PATH *2 + 2)

It doesn't seem to be needed? (The code works fine without it).
And there's no FreeMemory command for it? Is it a leftover? :)

Posted: Sat Aug 02, 2008 12:37 pm
by Sparkie
Yes PB, it's a remnant from earlier code. I edited and removed that line. Thanks for spotting that one.

I am still working on getting the URL on startup. It turned out not to be as easy as I had hoped. :evil:

@Pantcho!!: Thanks for the kind words. :)

Posted: Thu Dec 25, 2008 5:16 pm
by besko
Sparkie
Do you have code for Opera and Google Chrome?




And how can i Hook Url?
and do something when i Hook www.google.com?



tnx for help :)