Hook text in WebGadgets

Just starting out? Need help? Post your questions and find answers here.
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Hook text in WebGadgets

Post by Wolf »

How can we hook or other way to get texts in an WebGadget in external program like internet explorer?

I use some code from Sparkie for all text gadgets and work perfect with all gadgets but don't work on WebGadgets.

We have of example internet explorer program handle of window and class name.

Class name is "Internet Explorer_Server" in internet explorer.

Now how can we hook text from it ?
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Hi Wolf :)

Do you want all content, including HTML or just the text portions of the web page :?:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Post by Wolf »

Hi Sparkie :D

Thanks for reply. is better for me to get all content maybe i can then filter output :D

Thanks again.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

I'm not very good with PB Network commands, so I came up with this method instead. Needs some work but maybe it will help you. :)

No DLL / hook being used here. This code simply checks for the active (or last instance) of Internet Explorer, and downloads the URL source. The source is saved to a file and then displayed in an EditorGadget.

Code: Select all

Enumeration 
  #Window_0 
EndEnumeration 
Enumeration 
  #Text_0 
  #Editor_0 
  #Button_0 
EndEnumeration 
#MAX_URL = 2083 
; --> Procedure to find Internet Explorer address bar 
Procedure.l enumChildren(hwnd.l, lparam.l) 
  Shared previousURL$ 
  ; --> Find web address bar 
  childID = GetDlgCtrlID_(hwnd) 
  ; --> Not sure if ID is always 41477, but it works here 
  If childID = 41477 
    ; --> Allocate space for url and 
    URL$ = Space(#MAX_URL) 
    MemoryBuffer$ = Space(256) 
    ; --> Get url from address bar 
    SendMessage_(hwnd, #WM_GETTEXT, #MAX_URL, @URL$) 
    ; --> If URL has changed, get new info 
    If URL$ <> previousURL$ 
      ; --> Save the URL content to a local file 
      URLDownloadToFile_(0, URL$, "c:\url.txt", 0, 0) 
      ; --> read the file 
      ReadFile(0, "c:\url.txt") 
      ; --> Clear EditorGadget 
      ClearGadgetItemList(#Editor_0) 
      Repeat 
        dataLength = ReadData(@MemoryBuffer$, 256) 
        ; --> Add text to EditorGadget 
        AddGadgetItem(#Editor_0, -1, PeekS(@MemoryBuffer$)) 
      Until dataLength = 0 
      CloseFile(0) 
    EndIf 
    SetGadgetText(#Text_0, "Current URL is: " + URL$) 
    previousURL$ = URL$ 
    ProcedureReturn 0 
  Else 
    ProcedureReturn 1 
  EndIf 
EndProcedure 
; --> Procedure to find Internet Explorer window 
Procedure checkIE() 
  SetGadgetText(#Text_0, "Looking for Internet Explorer") 
  ieWindow = FindWindow_("IEFrame", 0) 
  EnumChildWindows_(ieWindow, @enumChildren(), 0) 
EndProcedure 
If OpenWindow(#Window_0, 0, 300, 550, 150, #PB_Window_SystemMenu, "Get URL content") And CreateGadgetList(WindowID(0)) 
  ButtonGadget(#Button_0, 10, 5, 100, 20, "Start URL check") 
  TextGadget(#Text_0, 10, 30, 400, 40, "") 
  EditorGadget(#Editor_0, 0, 70, 550, 80) 
  ; --> We'll use a 256k MAX input for now. Adjust to your liking ;) 
  SendMessage_(GadgetID(#Editor_0), #EM_EXLIMITTEXT, 0, 262144) 
  ; --> Keep our window on top 
  SetWindowPos_(WindowID(#Window_0), #HWND_TOPMOST, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE) 
  Repeat 
    event = WaitWindowEvent() 
    If event = #PB_EventGadget And EventGadgetID() = #Button_0 
      Select GetGadgetText(#Button_0) 
        Case "Stop URL check" 
          KillTimer_(WindowID(#Window_0), 1) 
          timerActive = #False
          SetGadgetText(#Text_0, "") 
          SetGadgetText(#Button_0, "Start URL check") 
        Case "Start URL check" 
          checkIE() 
          ; --> I'll use a 5 second timer to check for Internet Explorer window
          SetTimer_(WindowID(#Window_0), 1, 5000, @checkIE()) 
          timerActive = #True
          SetGadgetText(#Button_0, "Stop URL check") 
      EndSelect 
    EndIf 
  Until event = #PB_Event_CloseWindow 
  ; --> Delete our temporary downloaded file 
  If timerActive
    KillTimer_(WindowID(#Window_0), 1)
  EndIf
  If FileSize("c:\url.txt") > -1 
    DeleteFile("c:\url.txt") 
  EndIf 
EndIf 
End 
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Wolf
Enthusiast
Enthusiast
Posts: 232
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Post by Wolf »

um, thanks but i want get this texts example in one program are using internet explorer server class to show html text. for example my IM chat window.

I sent for you some information today in private message please read it, maybe it can help to you to understanding what's my mean. Vb source is include :D
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Hook text in WebGadgets

Post by Kwai chang caine »

I have found that i search but the SPARKIE code not works here
I have try to convert of 3.94 to 4.51, it's perhaps that ..

I have modify this line

Code: Select all

 If childID = 41477 Or childID = 40965 Or childID = 40960
because me i have three different childID

What's wrong..i not found :(
Thanks to your help

Code: Select all

; http://www.purebasic.fr/english/viewtopic.php?p=77543#p77543

Enumeration 
  #Window_0 
EndEnumeration 
Enumeration 
  #Text_0 
  #Editor_0 
  #Button_0 
 EndEnumeration
 
#MAX_URL = 2083 
Global FileTxt.s = GetTemporaryDirectory() + "url.txt"

; --> Procedure to find Internet Explorer address bar 
Procedure.l enumChildren(hwnd.l, lparam.l) 
  Shared previousURL$ 
  ; --> Find web address bar 
  childID = GetDlgCtrlID_(hwnd)
  
  Debug childID  ; --> Not sure if ID is always 41477, but it works here
  
  If childID = 41477 Or childID = 40965 Or childID = 40960
    ; --> Allocate space for url and 
    URL$ = Space(#MAX_URL) 
    MemoryBuffer$ = Space(256) 
    ; --> Get url from address bar 
    SendMessage_(hwnd, #WM_GETTEXT, #MAX_URL, @URL$) 
    Debug URL$
    ; --> If URL has changed, get new info 
    If URL$ <> previousURL$ 
      ; --> Save the URL content to a local file 
      URLDownloadToFile_(0, URL$, FileTxt, 0, 0) 
      ; --> read the file 
      If ReadFile(0, FileTxt) 
       ; --> Clear EditorGadget 
       ClearGadgetItems(#Editor_0) 
       Repeat 
        dataLength = ReadData(0,@MemoryBuffer$, 256) 
        ; --> Add text to EditorGadget 
        AddGadgetItem(#Editor_0, -1, PeekS(@MemoryBuffer$)) 
       Until dataLength = 0 
       CloseFile(0)
      Else
       Debug "Impossible To Read the file"
     EndIf  
    EndIf 
    SetGadgetText(#Text_0, "Current URL is: " + URL$) 
    previousURL$ = URL$ 
    ProcedureReturn 0 
  Else 
    ProcedureReturn 1 
  EndIf 
EndProcedure 
; --> Procedure to find Internet Explorer window 
Procedure checkIE() 
 SetGadgetText(#Text_0, "Looking for Internet Explorer") 
 ieWindow = FindWindow_("IEFrame", 0) 
 EnumChildWindows_(ieWindow, @enumChildren(), 0) 
EndProcedure
 
If OpenWindow(#Window_0, 0, 300, 550, 150, "Get URL content", #PB_Window_SystemMenu) 
  ButtonGadget(#Button_0, 10, 5, 100, 20, "Start URL check") 
  TextGadget(#Text_0, 10, 30, 400, 40, "") 
  EditorGadget(#Editor_0, 0, 70, 550, 80) 
  ; --> We'll use a 256k MAX input for now. Adjust to your liking ;) 
  SendMessage_(GadgetID(#Editor_0), #EM_EXLIMITTEXT, 0, 262144) 
  ; --> Keep our window on top 
  SetWindowPos_(WindowID(#Window_0), #HWND_TOPMOST, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE) 
  Repeat 
    event = WaitWindowEvent() 
    If event = #PB_Event_Gadget And EventGadget() = #Button_0 
      Select GetGadgetText(#Button_0) 
        Case "Stop URL check" 
          KillTimer_(WindowID(#Window_0), 1) 
          timerActive = #False 
          SetGadgetText(#Text_0, "") 
          SetGadgetText(#Button_0, "Start URL check") 
        Case "Start URL check" 
          checkIE() 
          ; --> I'll use a 5 second timer to check for Internet Explorer window 
          SetTimer_(WindowID(#Window_0), 1, 5000, @checkIE()) 
          timerActive = #True 
          SetGadgetText(#Button_0, "Stop URL check") 
      EndSelect 
    EndIf 
  Until event = #PB_Event_CloseWindow 
  ; --> Delete our temporary downloaded file 
  If timerActive 
    KillTimer_(WindowID(#Window_0), 1) 
  EndIf 
  If FileSize(FileTxt) > -1 
    DeleteFile(FileTxt) 
  EndIf 
EndIf 
End 
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Hook text in WebGadgets

Post by Kwai chang caine »

Nobody have a start of beginning of little, very small idea ??? :(
ImageThe happiness is a road...
Not a destination
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Hook text in WebGadgets

Post by IdeasVacuum »

Can only see a potential problem

FindWindow_("IEFrame", 0). IEFrame does not necessarily exist, depending on the I.E. version. It's tricky to find the main Titlebar too, because it includes the name of the current website (so, best to impose the title bar title by getting I.E. to load a local html page). The childID is not necessarily 41477 - on my PC, running IE8, 41477 is found but the URL is not collected....

Edit: on top of that of course, I.E. would need to be available. If the website concerned was based on dear old flash, that would not work either.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Hook text in WebGadgets

Post by Kwai chang caine »

Thanks a lot IdeasVacuum 8)

Apparently this code is not really at the top, and not works at each time :(
I'm sad because, when i have see SPARKIE code, i thought for a moment have find what i searching :(

I continue to search a code who give the source and adress of all the internet page..even the POPUP

Thanks again to your answer
Have a good day 8)
ImageThe happiness is a road...
Not a destination
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Hook text in WebGadgets

Post by RASHAD »

Sparkie Code
Modified By RASHAD
For Windows XP

Code: Select all

Enumeration 
  #Window_0 
EndEnumeration 
Enumeration 
  #Text_0 
  #Editor_0 
  #Button_0 
EndEnumeration 
#MAX_URL = 2083 
; --> Procedure to find Internet Explorer address bar 
Procedure.l enumChildren(hwnd.l, lparam.l) 
  Shared previousURL$ 
  ; --> Find web address bar 
  childID = GetDlgCtrlID_(hwnd)
  ; --> Not sure if ID is always 41477, but it works here 
  If childID = 41477 
    ; --> Allocate space for url and 
    URL$ = Space(#MAX_URL) 
    MemoryBuffer$ = Space(256) 
    ; --> Get url from address bar 
    SendMessage_(hwnd, #WM_GETTEXT, #MAX_URL, @URL$) 
    ; --> If URL has changed, get new info 
;     If URL$ <> previousURL$ 
;       ; --> Save the URL content to a local file 
;       URLDownloadToFile_(0, URL$, "c:\url.txt", 0, 0) 
;       ; --> read the file 
;       ReadFile(0, "c:\url.txt") 
;       ; --> Clear EditorGadget 
;       ClearGadgetItems(#Editor_0) 
; ;       Repeat 
; ;         dataLength = ReadData(0,@MemoryBuffer$, 256) 
; ;         ; --> Add text to EditorGadget 
; ;         AddGadgetItem(#Editor_0, -1, PeekS(@MemoryBuffer$)) 
; ;       Until dataLength = 0 
;       ;CloseFile(0) 
;     EndIf 
    SetGadgetText(#Text_0, "Current URL is: " + URL$) 
    previousURL$ = URL$ 
    ProcedureReturn 0 
  Else 
    ProcedureReturn 1 
  EndIf 
EndProcedure 
; --> Procedure to find Internet Explorer window 
Procedure checkIE() 
  SetGadgetText(#Text_0, "Looking for Internet Explorer") 
  ieWindow = FindWindow_("IEFrame", 0) 
  EnumChildWindows_(ieWindow, @enumChildren(), 0) 
EndProcedure 
If OpenWindow(#Window_0, 0, 300, 550, 150, "Get URL content", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ButtonGadget(#Button_0, 10, 5, 100, 20, "Start URL check") 
  TextGadget(#Text_0, 10, 30, 400, 40, "") 
  EditorGadget(#Editor_0, 0, 70, 550, 80) 
  ; --> We'll use a 256k MAX input for now. Adjust to your liking ;) 
  SendMessage_(GadgetID(#Editor_0), #EM_EXLIMITTEXT, 0, 262144) 
  ; --> Keep our window on top 
  SetWindowPos_(WindowID(#Window_0), #HWND_TOPMOST, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE) 
  Repeat 
    event = WaitWindowEvent() 
    If event = #PB_Event_Gadget And EventGadget() = #Button_0 
      Select GetGadgetText(#Button_0) 
        Case "Stop URL check" 
          KillTimer_(WindowID(#Window_0), 1) 
          timerActive = #False
          SetGadgetText(#Text_0, "") 
          SetGadgetText(#Button_0, "Start URL check") 
        Case "Start URL check" 
          checkIE() 
          ; --> I'll use a 5 second timer to check for Internet Explorer window
          SetTimer_(WindowID(#Window_0), 1, 5000, @checkIE()) 
          timerActive = #True
          SetGadgetText(#Button_0, "Stop URL check") 
      EndSelect 
    EndIf 
  Until event = #PB_Event_CloseWindow 
  ; --> Delete our temporary downloaded file 
  If timerActive
    KillTimer_(WindowID(#Window_0), 1)
  EndIf
  If FileSize("c:\url.txt") > -1 
    DeleteFile("c:\url.txt") 
  EndIf 
EndIf 
End 
Egypt my love
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Hook text in WebGadgets

Post by Kwai chang caine »

Thanks a lot my friend 8)

But i have testing your code on WinXP and with IE7, and the code go to the line

Code: Select all

SetGadgetText(#Text_0, "Current URL is: " + URL$)
But there are nothing in URL$ :(

Apparently like say IDEASVACUUM the line

Code: Select all

SendMessage_(hwnd, #WM_GETTEXT, #MAX_URL, @URL$)
not works very well :(

Again thanks for have try to help me 8)
Last edited by Kwai chang caine on Fri Dec 30, 2011 3:03 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: Hook text in WebGadgets

Post by RASHAD »

Next code tested with IE 6 & IE 8
It should work with IE 7

Code: Select all


Procedure EnumChildProc(hwnd, lParam)
  Protected Classname$ = Space(#MAX_PATH)
  ;Protected Textname$ = Space(#MAX_PATH)

    GetClassName_(hwnd, @Classname$, #MAX_PATH-1)
    ;GetWindowText_(hwnd, @Textname$, #MAX_PATH-1)
    If ClassName$ = "Edit"
      SendMessage_(hwnd,#EM_SETSEL,0,256)
      SendMessage_(hwnd,#WM_COPY,0,0)
      Debug GetClipboardText()
    EndIf 
 
  ProcedureReturn 1
EndProcedure
hwndParent = FindWindow_("IEFrame", 0)
EnumChildWindows_(hwndParent, @EnumChildProc(), 0)
Egypt my love
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: Hook text in WebGadgets

Post by flaith »

Tested under ie6 and ie8 : works
thanks Rashad :)
“Fear is a reaction. Courage is a decision.” - WC
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Hook text in WebGadgets

Post by Kwai chang caine »

Thanks a lot RASHAD, this time that works... :shock:
You are too strong !!!
Image

Thanks also FLAITH for testing :wink:
ImageThe happiness is a road...
Not a destination
Post Reply