Displaying Content in Internet Explorer
Many programmers have realized the benefits of using a browser ActiveX control within an OpenInsight form. HTML provides an easy way to deliver rich, flexible, and dynamic content. For example, this is a popular technique for building application dashboards.
There are occasions when an ActiveX browser control will not be ideal (or work at all.) A recent project required OpenInsight to display some rather complex reports that were created on-the-fly via a web service. In and of itself this was not a problem. We were able to make our request and get back the report within an XML wrapper. However, the HTML content included various elements that precluded the use of an ActiveX control, such as various dependencies upon the document object model (DOM). Therefore, another method for displaying HTML was required.
The Internet Explorer object provides us a way to launch an instance of Internet Explorer that is virtually under the control of OpenInsight. It shares the same methods and properties as the the ActiveX browser control so it will be somewhat familiar to many programmers. Comprehensive documentation can be found on the Microsoft Developer Network website.
In OpenInsight 7.1 and later you can use the Basic+ OLE/COM functionality to utilize this object. Earlier versions of OpenInsight require the assistance of third-party utilities such as our SRP_COM function. The following code samples will use the native Basic+ functionality but anyone who wishes to use SRP_COM will find that the syntax is remarkably similar.
As with any COM object we must first create an instance using the appropriate class:
Equ COMObject$ to 'InternetExplorer.Application' objIE = OLECreateInstance(COMObject$)
Once the object is created, the programmer may want to alter the way the browser appears to the end user. Note, however, that the Visible property should be turned off first in order to avoid showing the end user the preliminary changes:
OLEPutProperty(objIE, 'Visible', No$) ; // Hide the Window OLEPutProperty(objIE, 'Left', 200) ; // Set Window's leftmost edge OLEPutProperty(objIE, 'Top', 50) ; // Set Window's topmost edge OLEPutProperty(objIE, 'Height', 500) ; // Set the Window's height to 500 OLEPutProperty(objIE, 'Width', 300) ; // Set the Window's width to 300 OLEPutProperty(objIE, 'MenuBar', No$) ; // Hide Menu Bar OLEPutProperty(objIE, 'ToolBar', No$) ; // Hide Tool Bar OLEPutProperty(objIE, 'StatusBar', No$) ; // Hide Status Bar OLEPutProperty(objIE, 'Resizable', No$) ; // Hide Status Bar rv = OLECallMethod(objIE, 'Navigate', 'About:Blank') ; // Open blank page in browser
Whenever content is being loaded into the object you will want to give it an opportunity to finish before moving on. You can use the Busy property to accomplish this:
// Wait until the Explorer object says it is no longer busy Loop While OLEGetProperty(objIE, 'Busy') Repeat
In order to get the HTML content into the browser you need to get access to the internal Document object. This is done using the Document property. In this new object the appropriate methods and properties are available for our use (which can be linked to from the aforementioned MSDN article.) Note that since we are loading content into the object we should again wait for the object to finish before moving forward:
// Write HTML to the active IE Document objDoc = OLEGetProperty(objIE, 'Document') If objDoc then rv = OLECallMethod(objDoc, 'open') rv = OLECallMethod(objDoc, 'write', strBody) ; // Write the HTML content to the document OLEPutProperty(objDoc, 'Title', strTitle) ; // Update the Title of the browser rv = OLECallMethod(objDoc, 'close') end // Wait until the Explorer object says it is no longer busy Loop While OLEGetProperty(objIE, 'Busy') Repeat
Other actions may be needed but once everything is complete the programmer needs to remember to make the browser visible:
OLEPutProperty(objIE, 'Visible', Yes$)
At this point an Internet Explorer browser will appear pre-filled with the desired content. Please note that the above code does not contain any error checking. We recommend that the programmer add the proper logic to handle that.
Leave a Reply