Page 1 of 3

WebGadget DocumentComplete event

Posted: Sun Jul 18, 2004 10:28 am
by soerenkj
In Visual Basic the 'WebControl' fires a DocumentComplete event when a document has finished loading (see http://msdn.microsoft.com/workshop/brow ... frame=true)

Doesn't the WebGadget in PureBasic (or the IWebBrowser2 object 'inside' it) do something like this?
How do I make a handler for it?

Re: WebGadget DocumentComplete event

Posted: Sun Jul 18, 2004 5:35 pm
by NoahPhense

Code: Select all

#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, #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "WebGadget ReadyState") 

  If CreateStatusBar(0, WindowID()) 
    StatusBarText(0, 0, "") 
  EndIf 
      
  If CreateGadgetList(WindowID()) 
    WebGadget(0, 10, 10, 680, 460, "http://www.purebasic.com") 
    WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(0), #GWL_USERDATA) ; needed for accessing IWebBrowser interface 
  EndIf 
  
EndIf 

Repeat 

  Event = WaitWindowEvent() 
  
  If isBusy 
    WebObject\get_ReadyState(@isReady) 
      
      Select isReady 
        Case 1 
          StatusBarText(0, 0, "Page Loading") 
        Case 2 
          StatusBarText(0, 0, "Page Loaded") 
        Case 3 
          StatusBarText(0, 0, "Page is interactive with some data missing") 
        Case 4 
          StatusBarText(0, 0, "Page finished loading") 
      EndSelect 
  EndIf 
  
  WebObject\get_busy(@isBusy) 
  
Until Event = #PB_Event_CloseWindow 
    
End 
- np

Posted: Sun Jul 18, 2004 7:20 pm
by soerenkj
thanks, and sorry that I did not make my intention with the posting completely clear. My problem actually is not to find out when a document has finished loading - that was just an example. My problem is, quite generally, that I would like to be able to set up handlers for events that I think (?) the WebGadget should be firing.
If I just knew to which window these events are sent, I guess I could handle the events in a window callback for that window..

..

Posted: Sun Jul 18, 2004 7:24 pm
by NoahPhense
What type of events are you trying to catch?

- np

Posted: Sun Jul 18, 2004 7:57 pm
by soerenkj
all of them!
(but I am particularly interested in the DocumentComplete, as I want to avoid the busy waiting as in the code example you posted)

..

Posted: Sun Jul 18, 2004 10:49 pm
by NoahPhense
The WebBrowser Control fires the DocumentComplete event when the
document has completely loaded and the READYSTATE property has
changed to READYSTATE_COMPLETE.


Let's see if Freak can help..

- np

Posted: Mon Jul 19, 2004 12:44 am
by freak
Sorry, i have no idea how to connect to such events. :oops:

Timo

Posted: Mon Jul 19, 2004 1:50 am
by Sparkie
I've spent the entire weekend Googling my little a$$ off in hopes of figuring out all this IWebBrowser... IHTMLDocument2... IHTMLAnchorElement... IUnknown... DWebBrowserEvents2... IConnectionPointContainer... HTMLElementEvents2... blah...blah...blah :?

I have made some headway, but trying to convert c... c++... ATL... VB... VC... XYZ... DoBeDoBeDo code to PB has me going insane. 8O

I'm making some progress but don't hold your breath waiting for any results. :P

..

Posted: Mon Jul 19, 2004 4:55 pm
by NoahPhense
freak wrote:Sorry, i have no idea how to connect to such events. :oops:

Timo
Maybe you could point us to the IWebBrowser2 structure/interface.. that
is built into pb? I know where the one is at MSDN.. but it seems that
the PB syntax differs a bit.

- np

Posted: Mon Jul 19, 2004 6:38 pm
by Nico
Solution seems to be DWebBrowserEvents2 Interface :

Link to MSDN:http://msdn.microsoft.com/library/defau ... vents2.asp


:)

Posted: Mon Jul 19, 2004 7:00 pm
by Sparkie
DWebBrowserEvents2 is just the tip of the iceberg Nico. :(

I'm inching along ever so s...l...o...w...l...y. At this point, I think I have converted 75% of what we need. 8) I can see events (I think) as they happen but I don't know which events they are 8O

Here's what I'm trying to understand/convert. That is one of several I'm working with but it has moved me along the furthest.

..

Posted: Mon Jul 19, 2004 8:01 pm
by NoahPhense
ok.. try this out..

use the interface generator on your SHDOCVW.DLL

the one in your system32 dir..

im still tooling with it.. we'll see

- np

Posted: Mon Jul 19, 2004 8:44 pm
by Sparkie
Thanks np, I looked at it but I'm not sure what the InterfaceGenerator will do in this situation that Fred & Co. haven't already done :D

From what I've seen so far via the PB Interface viewer, all needed interfaces for this are already defined in PB. Am I missing something here :?: :?

..

Posted: Tue Jul 20, 2004 12:54 am
by NoahPhense
Ok, I've got the solution. There's only one catch,
it's in C++ and *I'm* not converting it..

I have the entire project source, the dsp, dsw, etc..

We really only need like 2 maybe 3 procedures out of it..

Code: Select all

// Document loaded and initialized

void SimpleBrowser::_OnDocumentComplete(LPDISPATCH lpDisp,VARIANT *URL)
{
    if (lpDisp == _BrowserDispatch) {

		CString URL_string;
		
		if ((URL       != NULL) &&
            (V_VT(URL) == VT_BSTR)) {
			URL_string = V_BSTR(URL);
        }

        OnDocumentComplete(URL_string);

    }    
}

void SimpleBrowser::OnDocumentComplete(CString URL)
{
	CWnd *parent = GetParent();
	
	if (parent != NULL) {

		Notification	notification(m_hWnd,GetDlgCtrlID(),DocumentComplete);
		
		notification.URL = URL;

		LRESULT result = parent->SendMessage(WM_NOTIFY,
		                                     notification.hdr.idFrom,
											 (LPARAM)&notification);
		
	}
}
If someone wants to give it a whirl, I'll post the project.

- np

Posted: Tue Jul 20, 2004 1:31 am
by Sparkie
Thanks np. :P I can add that to the cpp code I dl'd from Incorporating the WebBrowser Control into Your Program. The sample code is located at the top of that page in a self-extracting zip.

The page actually does a pretty good job of explaining the interfaces needed for certain tasks, so once we break through the cpp barrier we could be a few steps closer to success. 8)

After looking at the cpp code, I have a much greater appreciation for Fred & Co. and the ease of coding in PB! :D