WebGadget DocumentComplete event

Just starting out? Need help? Post your questions and find answers here.
soerenkj
User
User
Posts: 95
Joined: Mon Jun 14, 2004 10:19 pm

WebGadget DocumentComplete event

Post 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?
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: WebGadget DocumentComplete event

Post 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
Last edited by NoahPhense on Sun Jul 18, 2004 9:55 pm, edited 1 time in total.
soerenkj
User
User
Posts: 95
Joined: Mon Jun 14, 2004 10:19 pm

Post 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..
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post by NoahPhense »

What type of events are you trying to catch?

- np
soerenkj
User
User
Posts: 95
Joined: Mon Jun 14, 2004 10:19 pm

Post 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)
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Sorry, i have no idea how to connect to such events. :oops:

Timo
quidquid Latine dictum sit altum videtur
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post 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
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Post by Nico »

Solution seems to be DWebBrowserEvents2 Interface :

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


:)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post 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
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 :?: :?
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

..

Post 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
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply