Web Pages From Resources
This is a sample HTML page that would be included as a resource with an ASCOM driver. The code in
the driver can use the Internet Explorer res: protocol to load this page from the resources in the driver exe/dll file.
The embedded image uses a src= of just the image file name. This is a relative reference, therefore it inherits the res://exe file/ URI and it correctly resolves from the exe/dll file's references as well! This allows you to develop the web page in a directory and see the embedded images, yet still works when the HTML is loaded via the res: protocol at run time. For more information see the following MSDN articles:
res:// Protocol
Cutting Edge: Pluggable Protocols
Step by step
- Develop your web page with all images and other components in a single directory somewhere. Use relative URIs for all components that will be embedded in the resources. Of course you can use full URIs (e.g., http://xxx/) for links to regular web pages. Validate the HTML and links.
- Prepare a resource script (.RC file) that lists each component. The main trick is to have the resource names equal to the file names. The resource script (.rc file) for this page is:
readme.html 23 "readme.html"
Bug72T-sm.jpg 23 "Bug72T-sm.jpg"
The resource type of 23 is HTML and is the default resource type for the res: protocol, thus you do not need a resource type in the res: URI.
- Compile the resource script into a binary resource (.RES) file. The Microsoft Resource Compiler (RC.EXE) will do this, and there are other freeware resource compilers out there. Note you cannot use the VB6 add-in resource editor to create the binary resource file, as it cannot create resources with HTML (23) type. For VC++6 and .NET projects, you can skip this step as the IDE will automatically compile the .RC file and embed it into your EXE or DLL.
- Create an instance of SHDocVw.InternetExplorer, at a minimum set its Visible property to True, then use its Navigate() method to open your web page (HTML) using the res: protocol. Since you designated all of your resources as type 23 (HTML), the starting URI does not have to contain a resource type. An example of the URI to pass to SHDocVw.InternetExplorer.Navigate() is:
XX.Navigate("res://C:\Program Files\Common Files\ASCOM\Telescope\MammaJamma Driver.exe/main.html"
- Once the browser appears, your program or driver can just go on about its business or exit. The browser starts as a separate executable and remains alive until closed by the user. The SHDocVw object can be released.