Microsoft HTML Help - Get the topic page URL from the topic ID

1.4k views Asked by At

We're currently using HTML Help to display CHM help files in our software. We'd like to change how we're opening the help however, to open it in our own custom window with an embedded browser.

Achieving this by directly requesting topic pages to be opened with URLs is straightforward enough, however, we'd like to maintain the usage of Topic IDs such that the editorial team can freely re-structure and re-name the help as they see fit, only by manipulating the maps and aliases.

I've been digging around for a bit and couldn't find any (reasonably cheap) way to get a URL to open from a Topic ID, such that I could request a URL to open in the custom window. Am I missing a trick, or are there any libraries out there that might facilitate this?

1

There are 1 answers

1
help-info.de On

AFAIK you need a valid URL with the topic filename e.g. "Garden/garden.htm" when using a web browser control. So other solutions are very difficult and I think not possible with a web browser control.

You know you can do a hard coded call with e.g. following code:

    public static string GetChmUrl(string fileName, string page)
{
  StringBuilder url = new StringBuilder();
  url.AppendFormat("mk:@MSITStore:{0}::", fileName);
  if (page.IndexOf('/') != 0) url.Append('/');
  url.Append(page);
  return url.ToString();
}

and

   webBrowser1.Navigate(new Uri(GetChmUrl(Application.StartupPath + sHTMLHelpFileName_ShowWithoutAutoSync, "Garden/garden.htm")));

For showing HTMLHelp topics by TopicId without the full blown help window you may create a special window type for the HTMLHelp Viewer window. OK – this is more a help authoring work preparing a call from your application. It’s possible by compiling the CHM in a special way and reduce it to the content pane normally on the right side of the HTMLHelp Viewer.

You can call the content by TopicId and the result is shown in the snapshot:

    private void btnTopicId_Click(object sender, EventArgs e)
{
    Help.ShowHelp(this.btnOpenHelpShowTopic, helpProvider1.HelpNamespace, HelpNavigator.TopicId, @"10000");
}

enter image description here

Many years ago there was a so called “embedded help” for application as you can see in the snapshot. This was done by HTMLHelp API call. I have old Delphi code but not translated to .net. HTMLHelp is used for nearly 20 years now and today there is more use of web help. So you have to think about and decide.

enter image description here

You need to use marshalling to call the unmanaged HTML Help API from a Visual C# application. Using HTMLHelp API in .net is not easy. To give this a try you may start with a download sample (at the end of the article) from: https://support.microsoft.com/en-us/kb/317406

I attached a snapshot too:

enter image description here

HTH.