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

好久不见. 提交于 2019-12-13 04:01:23

问题


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:


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");
}

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.

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:

HTH.



来源:https://stackoverflow.com/questions/31969356/microsoft-html-help-get-the-topic-page-url-from-the-topic-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!