Page 1 of 1

WebBrowser ActiveX + waiting until loading is complete

Posted: 26 Sep 2013 10:19
by Tonton Luc

What clause do I need to wait until get_Busy() = true ?
Any other way to use a timer ?
Here is a part of my actual code :

Code: Select all

facts - mem_timer mem_timer:(string Action,timerId,string Marque). clauses     onShow(_Source, _Data) :-         retractFactDb(mem_timer),         %         %  Create ActiveX control container and WebBrowser control inside         %         Container = activeXContainer::new(This:getVpiWindow()),         Container:attachListener(browserListener),         Obj=Container:createControl(webBrowser::componentClassID,Rct,idc_browser),         if not(Obj=uncheckedConvert(iOleObject_native,null)) then             _=Obj:queryInterface(iWebBrowser2_native::iid,IUnk),             IDisp=uncheckedConvert(iWebBrowser2_native,IUnk),             browser := iWebBrowser2_import::new(IDisp),             HomePage = "",             browser:navigate(HomePage,comDomains::unsigned(0x0),comDomains::null,comDomains::null,comDomains::null),             Id = timerSet(10),             assertz(mem_timer("end navigate",Id,"my_site"))         end if         .   predicates     onTimer : window::timerListener. clauses     onTimer(_Source, TimerId):-         timerKill(TimerId),         mem_timer(Action,TimerId,Marque),         retractall(mem_timer(Action,TimerId,Marque)),         if Action = "end navigate" and Marque = "my_site" then             OQP = browser:get_Busy(),             if OQP = true() then                 NewId = timerSet(50),                 assertz(mem_timer(Action,NewId,Marque))             else                 programControl::sleep(1000),                 traiter(Marque)             end if         end if,         !.

Posted: 26 Sep 2013 16:58
by dominique f pannier
Hi Tonton,

Instead of creating a Webbrowser control with the method detailed in the show event, you can add in your window by the IDE a control webBrowserControl if you work with VIP7.4.
Its interface supports a webBrowser object in the interface of which you'll find a set of various properties, and espacially the navigateComplete2Event property, which fires after a navigation to a link is completed on a window element or a frameSet element.

This property is an

Code: Select all

event2{object Source, iDispatch PDisp, variant URL}
that you control in your window by adding :

Code: Select all

for instance.
And then, the end of the navigation's event is captured.
I suppose it was you goal.

Posted: 27 Sep 2013 6:53
by Tonton Luc
Hi Dominiq,

Exactly what I need ...but I've only VIP 7.3 => any WebBrowserControl.

Posted: 27 Sep 2013 8:50
by dominique f pannier
With VIP7.3 , the job is not easy.
Like the webBrowser project of the (old) example package shows it, you can add in your window :

Code: Select all

predicates      browserListener : activeXContainer::activeXEventListener.         clauses      browserListener(_CtrlID,DispId,DispParams,_ExcepInfo,_ArgError)=winErrors::s_ok:-           ...           Var_list=toVariant_list(DispParams),           Var_list=[StatusTextVariant],           StatusTextVariant=comDomains::string(StatusText),      ...   predicates      toVariant_list : (comDomains::comDispParams) -> comDomains::variant* procedure (i). clauses      toVariant_list(ComDispParams)=DispParam_List:-          ComDispParams=comDomains::comDispParams(Array,_NamedArray,NArgs,_NamedArgs),          extractParameters(0,NArgs,Array,[],DispParam_List).         predicates      extractParameters : (           unsigned Idx,           unsigned Count,           pointer Array,           comDomains::variant* Buff,           comDomains::variant*)           procedure (i,i,i,i,o).         clauses       extractParameters(N,N,_Array,L,L):-           !.       extractParameters(N,Count,Array,Buff,List):-            PParam=uncheckedConvert(unsigned,Array)+sizeOfDomain(comDomains::comVariant)*N,            Head=variant::toVariant(uncheckedConvert(comDomains::comVariant,uncheckedConvert(pointer,PParam))),            N1=N+1,            extractParameters(N1,Count,Array,[Head|Buff],List).    
The click upon a link fires a lot of events which are captured by the browserListener.
DispID identifies the number of the event, and with the variable DispParams you can access to the text diplayed in the status line like described above.

Then you can build a strategy from these informations.

Posted: 27 Sep 2013 15:00
by Tonton Luc

Exactly what I need !!!
Many thanks for your help.
Have a good w-end.