Text of INPUT elements in webgadget
Posted: Wed May 13, 2009 2:33 pm
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.
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