Code : Tout sélectionner
Procedure SetHtml(Browser.IWebBrowser2,Texte.s)
Protected DocumentDispatch.IDispatch,Document2.IHTMLDocument2,Element.IHTMLElement
Protected Busy.l,Ret=0
If Browser
If Browser\Get_Busy(@Busy) = #S_OK
If Busy= #VARIANT_FALSE
If Browser\get_Document(@DocumentDispatch.IDispatch)=#S_OK And DocumentDispatch
If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2,@Document2.IHTMLDocument2)=#S_OK And Document2
If Document2\get_body(@Element.IHTMLElement)=#S_OK And Element
If Element\put_innerHTML(Texte)=#S_OK
Ret=1
EndIf
Element\Release()
EndIf
Document2\Release()
EndIf
DocumentDispatch\Release()
EndIf
EndIf
Else
MessageRequester ( "Info" , "Attendez que la page soit chargée" )
EndIf
EndIf
ProcedureReturn Ret
EndProcedure
Procedure.s GetHtml(Browser.IWebBrowser2)
Protected DocumentDispatch.IDispatch,Document2.IHTMLDocument2,Element.IHTMLElement
Protected Busy.l,*Bstr.i
Protected Texte.s=""
If Browser
If Browser\Get_Busy(@Busy.l) = #S_OK
If Busy= #VARIANT_FALSE
If Browser\get_Document(@DocumentDispatch.IDispatch)=#S_OK And DocumentDispatch
If DocumentDispatch\QueryInterface(?IID_IHTMLDocument2,@Document2.IHTMLDocument2)=#S_OK And Document2
If Document2\get_body(@Element.IHTMLElement)=#S_OK And Element
If Element\get_innerHTML(@*Bstr)=#S_OK And *Bstr
Texte.s=PeekS(*Bstr,-1, #PB_Unicode)
SysFreeString_(*Bstr)
EndIf
Element\Release()
EndIf
Document2\Release()
EndIf
DocumentDispatch\Release()
EndIf
EndIf
Else
MessageRequester ( "Info" , "Attendez que la page soit chargée" )
EndIf
EndIf
ProcedureReturn Texte
EndProcedure
Enumeration
#Window
#Web
#Button1
EndEnumeration
If OpenWindow(#Window,0,0,800,400,"Web",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(#Window))
WebGadget(#Web,0,0,800,360,"")
ButtonGadget(#Button1,10,370,100,20,"Modifier la Page")
SetGadgetText(#Web,"http://www.purebasic.fr/french/")
Browser.IWebBrowser2=GetWindowLong_(GadgetID(#Web),#GWL_USERDATA)
Repeat
Event=WaitWindowEvent()
If Event=#PB_Event_Gadget
Select EventGadget()
Case #Button1
Texte.s=GetHtml(Browser)
Texte="<h1><center><font color='#FF0000'>Bienvenue sur le Forum de PureBasic</font></center></h1></BR>"+Texte
SetHtml(Browser,Texte)
EndSelect
EndIf
Until Event=#PB_Event_CloseWindow
EndIf
DataSection
IID_IHTMLDocument2: ; {332C4425-26CB-11D0-B483-00C04FD90119}
Data.l $332C4425
Data.w $26CB,$11D0
Data.b $B4,$83,$00,$C0,$4F,$D9,$01,$19
EndDataSection