Different Ways to Use a Browser
In a client/server situation, the browser is going to become a lot more than just a way of viewing static pages. It actually becomes part of the application, and so we need to be aware of some of the other ways it can be used. For example, we can embed the browser inside another application, or use a special control called the Web Browser Control that comes as part of the Internet Explorer controls installation.
Alternatively, we can embed other applications within the Web browser, although this gives us only limited opportunity for adding extra features to our applications. We can even use a control called the Internet Transfer Control, that allows us to retrieve pages from the server without actually displaying them—but we can then get at the information in the HTTP stream, the HTML code, and the text contents. You'll see example of this control's use, and embedding a browser in a Visual Basic application, in the Case Study in Chapter 14.
Embedding a Browser within an Application
Typical web browsing involves either surfing from one site to another, or searching for specific information. In many situations, the user simply types in a URL, or clicks on previously defined bookmarks. While this is simple enough, it isn't the most user-friendly method. And if you have a set of predefined sites that the users go to regularly—such as the technical catalogue menu on your Intranet or a shares value monitor on the 'Net as a whole—how do you keep the lists up to date?
Microsoft's Internet Explorer is actually an object, and the program
IExplore.exe that we run to start it is just a shell. We can create our own instances of the
InternetExplorer object in code in Visual Basic, or most other languages. By embedding the browser within another application like this we have the ability to create a lightweight shell, and maintain dynamic content within that shell.
This has many advantages. For example it can give us a standard corporate interface with pop-up forms, and extra features. The regularly used sites can be catalogued and controlled by the application, even allowing the server administrator to shift all of the users from one site to another, without the clients even realizing that it is happening. Selecting certain sites could be entirely automatic, and the server can control the whole process. Of course, all these techniques are really Intranet-bound, where you can specify the client software directly.
Using the InternetExplorer.Application Object
Creating and controlling the browser in code is easy, and can be done from any application that supports Visual Basic for Applications, or most other programming languages. Here's an example that uses VBA:
Set TheBrowser = CreateObject("InternetExplorer.Application") TheBrowser.Visible = True
Once we've got the browser instance, and made it visible, we just use its methods and properties like any other object. Appendix F contains a list of the common ones, but here are a few examples:
TheBrowser.Navigate URL:= "http://www.wrox.com TheBrowser.Top = 100 'set the browser in the top TheBrowser.left = 100 'left of the user's screen TheBrowser.StatusBar = True 'display the status bar TheBrowser.GoSearch 'open the default Search page TheBrowser.GoHome 'open the default Home page TheBrowser.Refresh 'refresh the current page TheBrowser.Quit 'close the browser
Running an Application within the Browser
The browser will quite happily download and display different kinds of documents, as well as the usual defaults of
.txt files, and
.gif images. However, Internet Explorer will also handle standard office documents, like Word
.doc files and Excel
.xls speadsheets. It hosts a copy of the office application within it's own window, and displays it just like the original application would.
Here, we've used Word 97 to create a document, and saved it in Word's standard
.doc format. The template contains custom macros that manipulate the Office Assistant character, and produce a user guide:
This is really only useful in an Intranet environment, because of the size of the documents. And the user cannot normally edit the original, only the copy that is downloaded to their own browser. However, by maintaining local copies of templates, and loading files directly over the network (using the syntax
HREF="file://C:\Documents\Lunar.doc", for example) we can achieve a great deal this way.