Text of INPUT elements in webgadget

Share your advanced PureBasic knowledge/code with the community.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Text of INPUT elements in webgadget

Post by Hroudtwolf »

Hi,

I made a function which returns the text of input elements in webgadget.
Here is my result.

Have fun.

Regards
Wolf

PS: Enter a text in the keywords-field and press enter-key.

Code: Select all

 ; 2009 Hroudtwolf
; PureBasic-Lounge.com
; Windows
; PureBasic 4.x

Procedure.s GetElementText ( idWebGadget.i , sKey.s )
   Protected WebBrowser    .IWebBrowser2 = GetWindowLongPtr_( GadgetID ( idWebGadget ) , #GWL_USERDATA )
   Protected Dispatch      .iDispatch
   Protected Document      .IHTMLDocument3
   Protected Element       .IHTMLElement
   Protected InputElement  .IHTMLInputElement
   Protected bstrValue     .i
   Protected sValue        .s
 
   If Not ( WebBrowser\get_Document( @ Dispatch ) = #S_OK )
      Dispatch\Release() 
      ProcedureReturn ""
   EndIf
   If Not ( Dispatch\QueryInterface( ? IID_IHTMLDocument3 , @ Document ) = #S_OK )
      Document\Release()   
      Dispatch\Release()   
      ProcedureReturn ""
   EndIf
   If Not ( Document\getElementById( sKey , @ Element ) = #S_OK And Element )
      Document\Release()   
      Dispatch\Release()   
      ProcedureReturn ""
   EndIf
   If Not ( Element\QueryInterface( ? IID_IHTMLInputElement , @ InputElement ) = #S_OK)
      Element\Release()   
      Document\Release()   
      Dispatch\Release()   
      ProcedureReturn ""
   EndIf
   If Not ( InputElement\get_Value( @ bstrValue ) = #S_OK )
      Element\Release()   
      Document\Release()   
      Dispatch\Release()   
      ProcedureReturn ""
   EndIf
   
   InputElement\Release()   
   Element\Release()   
   Document\Release()   
   Dispatch\Release()   
   
   If Not bstrValue 
      ProcedureReturn ""
   EndIf 
     
   sValue = PeekS ( bstrValue , #PB_Any , #PB_Unicode )
   SysFreeString_( bstrValue )
         
   ProcedureReturn sValue     
EndProcedure

; ----- Testbereich -------

Procedure.i WebGadgetCB ( idGadget.i , sURL.s )
     
   ; The Input-Feld of the main searchform has the name "search_keywords".
   Debug GetElementText ( idGadget , "search_keywords" )
 
   ProcedureReturn #True
EndProcedure

Define.i idWindow
Define.i idWebGadget

idWindow    = OpenWindow ( #PB_Any , #PB_Ignore , #PB_Ignore , 800 , 600 , "test" , #PB_Window_ScreenCentered | #PB_Window_SystemMenu )
idWebGadget = WebGadget ( #PB_Any , 0 , 0 , 800 , 600 , "http://purebasic-lounge.com/search.php" )

SetGadgetAttribute ( idWebGadget , #PB_Web_NavigationCallback , @ WebGadgetCB () )

Repeat
   Select WaitWindowEvent ()
      Case #PB_Event_CloseWindow
      End
     
   EndSelect
ForEver

DataSection
  IID_IHTMLDocument3:      ; { 3050F485-98B5-11CF-BB82-00AA00BDCE0B }
  Data.l $3050F485
  Data.w $98B5 , $11CF
  Data.b $BB , $82 , $00 , $AA , $00 , $BD , $CE , $0B
  IID_IHTMLElement2:       ; { 3050f434-98b5-11cf-bb82-00aa00bdce0b }
  Data.l $3050F434
  Data.w $98B5 , $11CF
  Data.b $BB , $82 , $00 , $AA , $00 , $BD , $CE , $0B
  IID_IHTMLInputElement:   ; { 3050f5d2-98b5-11cf-bb82-00aa00bdce0b }
  Data.l $3050F5D2
  Data.w $98B5 , $11CF
  Data.b $BB , $82 , $00 , $AA , $00 , $BD , $CE , $0B
EndDataSection
User avatar
idle
Always Here
Always Here
Posts: 5912
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

great needed that!
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

Re: Text of INPUT elements in webgadget

Post by incaroad »

Hi Hroudtwolf!

How to do it on this website: http://www.tippmix.hu/sportfogadas

Thank you for your reply!
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Text of INPUT elements in webgadget

Post by walbus »

Last visited: Dec 2013

His website is down, more i know not
incaroad
User
User
Posts: 35
Joined: Sat Apr 20, 2013 2:58 pm
Location: Hungary; Pilisvörösvár

Re: Text of INPUT elements in webgadget

Post by incaroad »

:(

Someone else could help me?
How might rewrite the program this home page: (http://www.tippmix.hu/sportfogadas)
Many thanks!
Post Reply