C#打开CHM文件并定位到指定的页面(原创)
本来是使用.Net提供的Help类打开CHM文件,发现无法定位到指定的页面,记得有套Delphi写的系统,用API能打开并定位,于是找出Delphi版的源码翻译了过来,制成图文教程,受益大众,仅供参考:
C# Code:
/// <summary>
/// www.csframework.com C/S框架网
/// 作者:孙中吕
/// </summary>
public class CHMHelp
{
/// <summary>
/// 打开帮助
/// </summary>
/// <param name="helpFile">帮助文件。格式:xxx\test.chm, 或者:xxx\test.chm::/test/outline_0.htm</param>
public static void ShowHelp(string helpFile)
{
if (System.Environment.OSVersion.Platform == System.PlatformID.Win32NT)
{
HtmlHelpW(GetDesktopWindow(), helpFile, HH_DISPLAY_TOPIC, 0);//342342
}
else
{
HtmlHelpA(GetDesktopWindow(), helpFile, HH_DISPLAY_TOPIC, 0);//342342
}
}
[DllImport("hhctrl.ocx", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr HtmlHelpW(IntPtr hwnd, string HelpFile, int Command, int TopicID);
[DllImport("hhctrl.ocx", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr HtmlHelpA(IntPtr hwnd, string HelpFile, int Command, int TopicID);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr GetDesktopWindow();
public const int HH_DISPLAY_TOC = 0x0001;
public const int HH_DISPLAY_INDEX = 0x0002;
public const int HH_DISPLAY_SEARCH = 0x0003;
public const int HH_DISPLAY_TOPIC = 0x000;
}
参考文章:
使用DOC2CHM工具制作CHM帮助文件图解(原创)
源码下载: