progressbar avec un webgadget
Publié : jeu. 15/févr./2007 20:34
Comment faire fonctionner une barre de progression qui indique le chargement d'une page web dans un WebGadget?
Forums PureBasic - Français
http://forums.purebasic.com/french/
Code : Tout sélectionner
;/ Author : Pille
; Proxy like this : "192.168.0.1:8080"
Global Site.s="http://www.fdjeux.com/jeux/euromillions/euromillions_s_tirage.php"
ProcedureDLL.s Url2Text2(Url.s, OpenType.b,ProxyAndPort.s)
; 1 INTERNET_OPEN_TYPE_DIRECT Resolves all host names locally.
; 0 INTERNET_OPEN_TYPE_PRECONFIG Retrieves the proxy Or direct configuration from the registry.
; 4 INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY Retrieves the proxy Or direct configuration from the registry And prevents the use of a startup Microsoft JScript Or Internet Setup (INS) file.
; 3 INTERNET_OPEN_TYPE_PROXY Passes requests To the proxy unless a proxy bypass list is supplied And the name To be resolved bypasses the proxy. In this Case, the function uses INTERNET_OPEN_TYPE_DIRECT.
isLoop.b=1
INET_RELOAD.l = $80000000
hInet.l=0
hURL.l=0
Bytes.l=0
Buffer.s=Space(2048)
res.s=""
hInet = InternetOpen_("", OpenType, ProxyAndPort, "", 0)
hURL = InternetOpenUrl_(hInet, Url, #Null, 0, INET_RELOAD, 0)
Repeat
InternetReadFile_(hURL,@Buffer, Len(Buffer), @Bytes)
If Bytes = 0
isLoop=0
Else
res = res + Left(Buffer, Bytes)
EndIf
Until isLoop=0
InternetCloseHandle_(hURL)
InternetCloseHandle_(hInet)
ProcedureReturn res
EndProcedure
ProcedureDLL.s Url2Text(Url.s)
ProcedureReturn Url2Text2(Url,1,"")
EndProcedure
Procedure.s recup_loto() ; toute la page web est dans "Url2Text(#Site)"
Position = FindString(Url2Text(Site.s), "<DIV CLASS="+Chr($22)+"numero",1); on va filtrer les ligne de text
ligne$=Mid(Url2Text(Site.s),Position,220) ; pour trouver nos chiffres
For i= 1 To Len(ligne$)
car$=Mid(ligne$,i,1)
If Asc(car$)>48 And Asc(car$)<57 ; si on tombe sur des chiffres
car2$=car2$+car$ ; on garde
Else
car2$=car2$+"" ; sinon on ecrit rien
EndIf
If car$="<"
car2$=car2$+","
EndIf
Next i
; ***** petite bidouilles pour virer les virgules en trop ***********
car2$=ReplaceString( car2$,",,", ",")
car2$=Right(car2$,Len(car2$)-1)
car2$=ReplaceString( car2$,",,", "")
; ****************************************************
ProcedureReturn car2$
EndProcedure
;/ Test
MessageRequester(Site.s,Url2Text(Site.s))
OpenWindow(0,10,10,800,600,"resultat",#PB_Window_SystemMenu )
CreateGadgetList(WindowID(0))
EditorGadget(2, 10, 10, 800,580)
AddGadgetItem(2, -1, Url2Text(Site.s))
AddGadgetItem(2, -1, "les chiffres de l'euro million : "+recup_loto())
Repeat
Event=WindowEvent()
Until Event = #PB_Event_CloseWindow
Code : Tout sélectionner
Procedure Chargement1()
If OpenWindow(#Progress_0, 376, 189, 302, 81, "Chargement...", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_WindowCentered)
If CreateGadgetList(WindowID(#Progress_0))
ProgressBarGadget(#ProgressBar_charge, 30, 30, 250, 20, 0, CountGadgetItems(#Web_0)-1)
EndIf
EndIf
HideGadget(#Web_0, 1)
For charge=0 To CountGadgetItems(#Web_0)-1
SetGadgetState(#ProgressBar_charge, charge)
Next Charge
HideGadget(#Web_0, 0)
CloseWindow(#Progress_0)
SetGadgetText(#Web_0, GetGadgetText(#String_0))
EndProcedure
Code : Tout sélectionner
#READYSTATE_UNINITIALIZED = 0
; The control is waiting to be initialized
#READYSTATE_LOADING = 1
; The control is initializing itself through
; one Or more asynchronous properties. Some
; property values might not be available.
#READYSTATE_LOADED = 2
; The control has returned from IPersist*::Load
; so that all its properties are available And
; it has started any asynchronous Data transfers.
; The control's properties are available and it is
; ready To draw at least something through IViewObject::draw.
; Making properties available doesn't necessarily require
; The control's type information.
#READYSTATE_INTERACTIVE = 3
; The control is capable of interacting with the user in at
; least some limited sense And can supply its type information.
; Full interaction may not be available Until all asynchronous
; Data arrives
#READYSTATE_COMPLETE = 4
; The control is completely ready for all requests.
If OpenWindow(0, 10, 10, 700, 500, "WebGadget ReadyState", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
StatusBar= CreateStatusBar(0, WindowID(0))
If StatusBar
AddStatusBarField(120)
AddStatusBarField(300)
StatusBarText(0, 1, "")
EndIf
If CreateGadgetList(WindowID(0))
WebGadget(0, 10, 10, 680, 460, "http://www.purebasic.com")
WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA) ; needed for accessing IWebBrowser interface
ProgressBarGadget(1, 10, 6, 100, 12, 0, 100)
SetParent_(GadgetID(1), StatusBar)
EndIf
EndIf
count=0
Repeat
Event = WaitWindowEvent()
If isBusy
WebObject\get_ReadyState(@isReady)
Select isReady
Case 1
; il faudrait ajouter une fonction pour vérifier que l'accès internet est autorisé,
; afin de commencer le comptage.
If count<90
count=count+1
SetGadgetState(1,count)
EndIf
StatusBarText(0, 1, "Page Loading")
Case 2
StatusBarText(0, 1, "Page Loaded")
Case 3
StatusBarText(0, 1, "Page is interactive with some data missing")
Case 4
StatusBarText(0, 1, "Page finished loading")
SetGadgetState(1,100)
EndSelect
EndIf
WebObject\get_busy(@isBusy)
Until Event = #PB_Event_CloseWindow
End