OLE browser control for rendering html content (OpenInsight 32-Bit)
At 06 OCT 2009 07:56:49AM Richard Bright wrote:
I have been playing around with a form containing the simple OLE imbedded Web browser control - Navgate'.
I can happily replicate the appearance of Web publishing at the desktop using a crude method of forming the htmlContent, writing it to disk, then pointing the browser to the document ie
htmlContent=MyHtml_Doc
htmlFile=Drive():'\':'Html\HtmlDoc.htm'
OSWrite '' to htmlFileOsOpen htmlFile to hImagefile ThenOSWrite htmlContent to htmlFileOsClose hImagefileEnd
Call Send_Message(Win:'.OLECONTROL_1','Navigate',htmlFile)
But I would much prefer to just pass the htmlcontent directly to the control, missing the write-to-disk.
Ie something like SRP does in their great little example using a discrete web browser (see SRP Web Site)
objDoc=Get_Property(Win:'.OLECONTROL_1','Document')
If objDoc then
rv=OLECallMethod(objDoc, 'open')rv=OLECallMethod(objDoc, 'write', strBody) ; // Write the HTML content to the documentrv=OLECallMethod(objDoc, 'write', htmlContent)rv=OLECallMethod(objDoc, 'close')End
** or could I just do Call Send_Message(Win:'.OLECONTROL_1','write',htmlContent)
The SRP example inspired me; I tried to borrow from this but seem to be missing a line or two (or is it a page or two..) I guess I am just trying to sort out the correlation between Set_Property / Send_Message scripting for ocx controls imbedded in a form and RBasic plus script manipulation of methods / properties.
Any brave person kind enough to set out the steps that I need to do to get my form working?
Richard Bright
At 06 OCT 2009 08:06AM John Bouley wrote:
Richard,
Try this:
html=about:…your html…"
call send_message(@window:".OLECONTROL_1","NAVIGATE2",html)
The key here is using the "about:" syntax to trigger the control to display the embedded html. Thanks to Bob Carten.
HTH,
John
At 06 OCT 2009 09:14AM Bob Carten wrote:
Hi Richard,
I always
name the OLE control "BROWSER"
use Shell.Explorer as the text property of the OLE control
In the create event of the form
Call Send_Message(@window:'.BROWSER', 'Navigate2, 'about:blank')
This toggles the control into browser mode.
Then, when I want to set the html without using Navigate2 I use
x=Set_Property(@window:'.Browser', 'Document.Body.InnerHtml', myhtml)
If you want to get fancy you can an OLE event like BeforeNavigate2 and DownloadComplete,
embed urls like "about:blank?myParam1=foo&myParam2=bar", then put an ole event handler on the Browser control, intercept the navigate2, wait for document complete, then set 'document.body.innerhtml'
This lets you put hyperlinks in your page that call your programs without going to the web.
- Bob
Of course. the SRP control is always an option
At 06 OCT 2009 09:22AM [url=http://www.sprezzatura.com]The Sprezzatura Group[/url] wrote:
Richard,
We've been using this technique for quite some time now and one thing we've found is that all versions of the WB control are not created equal. Some versions let you get away with opening the document directly, but we've seen some versions GPF if the document object isn't instantiated first - I guess you can't open what doesn't exist, unless your version of IE is a bit more intelligent.
Generally this is the basic technique we use to display HTML - note how we navigate to "about:blank" first to ensure that the WB has a document object loaded….
0001 * Set some HTML into @window : ".IE" which is a basic 0002 * OLE control 0003 0004 html = "<html>" 0005 html := "<head>" 0006 html := "</head>" 0007 html := "<body>" 0008 html := "<form>" 0009 html := "<input type=text'></input>" 0010 html := "<input type=text'></input>" 0011 html := "<input type=text'></input>" 0012 html := "</body>" 0013 html := "</html>" 0014 0015 &nb
sp; call send_Message( @window : ".IE", "OLE.document.replace", "about:blank", "_self" ) 0016 call send_Message( @window : ".IE", "OLE.document.open" ) 0017 call send_Message( @window : ".IE", "OLE.document.write", html ) 0018 call send_Message( @window : ".IE", "OLE.document.close" )
World leaders in all things RevSoft
At 06 OCT 2009 09:25AM John Bouley wrote:
Thanks for the additional info Bob but shouldn't the set_property be send_message?
John
At 06 OCT 2009 02:28PM Martin Drenovac wrote:
All usefull stuff here - I have taken your code above as the create event and sure enough my 8.x system GPFs every time. Vista Prof with IE 8.x.
A simple ole control, text as "Shell.Explorer" as per Bob, so what could I have stuffed up in so few lines?
Cheers
At 06 OCT 2009 02:59PM [url=http://www.sprezzatura.com]The Sprezzatura Group[/url] wrote:
Hi Martyn,
You didn't stuff it up :) It's my fault for cutting and pasting from an old test window and assuming I hadn't been playing with the code!
Anyway, at least you've seen the problem with the document object not being loaded. Here's the proper code:
0001 equ READYSTATE_UNINITIALIZED$ to 0 0002 equ READYSTATE_LOADING$ to 1 0003 equ READYSTATE_LOADED$ to 2 0004 equ READYSTATE_INTERACTIVE$ to 3 0005 equ READYSTATE_COMPLETE$ to 4 0006 0007 html = "<html>" 0008 html := "<head>" 0009 html := "</head>" 0010 html := "<body>" 0011 html := "<form>" 0012 html := "<input type=text'></input>" 0013 html := "<input type=text'></input>" 0
014 html := "<input type=text'></input>" 0015 html := "</body>" 0016 html := "</html>" 0017 0018 * Navigate to the blank page and make sure it loads before 0019 * we try and go any further ( ReadyState == 4 ) 0020 call send_Message( @window : ".IE", "OLE.Navigate2", "about:blank" ) 0021 loop 0022 rs = get_Property( @window : ".IE", "OLE.ReadyState" ) 0023 while ( rs <> READYSTATE_COMPLETE$ ) 0024 call yield() 0025 repeat 0026 0027 call send_Mes
sage( @window : ".IE", "OLE.document.open" ) 0028 call send_Message( @window : ".IE", "OLE.document.write", html ) 0029 call send_Message( @window : ".IE", "OLE.document.close" )
World leaders in all things RevSoft
At 06 OCT 2009 03:32PM Martin Drenovac wrote:
Perfect - what a difference a few lines make.
Thank you..
At 07 OCT 2009 02:42PM dbakke@srpcs.com's Don Bakke wrote:
Of course. the SRP control is always an option
Just to clarify, there is no "SRP control" to speak of. Richard was referring to our article on controlling an external IE browser from within OI.
dbakke@srpcs.com
At 13 OCT 2009 04:39PM Richard Bright wrote:
Just an update on this thread - am working to integrate the most helpful pointers of Sprez and Bob Carten et al.
Now can load directly into browser object on form, offer hyperlinks, trap hyperlinks and reload - just need to sort out a backbrowser error and a little extra logic and then I am done.
Will post my solution for critique / refinement, and information for others that want to do this.
Richard Bright