Igence

igence and software

Our views, opinions and top tips on software development

Fun with ShellExecute

Monday, 16 June 2008

To provide context sensitive help for an application, it is quite useful to have HTML pages available which can be opened by the application when the user presses a key. To make things simple, it's also nice to have named anchors within the HTML so that the application doesn't need a separate page for each help item.

The obvious way to do this is to put the HTML files in a folder somewhere and use the Windows ShellExecute command to open the browser with the specified URL. If the pages can be fetched from a HTTP server, then there is no problem using named anchors, but if your pages are just files in a folder, you need to use the file: protocol. However, the file: protocol requires absolute paths, which means you need to know where your folder is. On top of that, you can't use named anchors either.

The solution I found is to get the application to create a temporary HTML file, on the fly, containing a meta refresh tag, which redirects to the URL (with the named anchor) you need. eg.


<meta HTTP-EQUIV="REFRESH" content="0; url=Help\Pages\Index.htm#subsection">


You then use ShellExecute to open the temporary file instead. If the temporary file has the extension .htm you don't need to specify the protocol because it uses the extension to determine that the file should be opened in the browser.

This means you can use a relative path and a named anchor.

Labels: , , ,


posted by Nige  # 10:32
Comments:

Post a Comment