1

我可以通过传递 ShortInteger 并将其转换为 dwData 参数的 Word 来打开 CHM 文件。IE

Unit Help;   //this is where the Id's are set with their description
 Interface
 Const

Address_File = 35;  //delphi identifies Address_File as a shortint
etc..


呼叫获取帮助传递我的 ID

GetHelp(Address_File); //call get help pass my ID to open to the Address_File topic


获取帮助程序

procedure GetHelp(HelpID : Word);
begin
  Application.HelpFile := ProgramPath + 'help.chm';
  HtmlHelpW(0, PWideChar(Application.HelpFile),HH_HELP_CONTEXT , HelpID);
end;


HtmlHelpW 函数

function HtmlHelpW(hwndCaller : HWND; pszFile: PWideChar; uCommand : Integer;
         dwData : DWORD) : HWND; stdcall; external 'hhctrl.ocx' name 'HtmlHelpW';

当我传递不同的 ShortIntegers 时,我可以在不同的部分初始化帮助文件。但是我无法弄清楚这些值是如何映射的。我希望能够映射到 chm 文件中的某些部分,但与它们关联的短整数或上下文 ID 未记录在程序中或未映射。

4

3 回答 3

6

Free Pascal 带有一个 chmls.exe 实用程序,它有一个尝试恢复别名(上下文)数据的命令:

chmls, a CHM utility. (c) 2010 Free Pascal core.

Usage: chmls [switches] [command] [command specific parameters]

Switches :
 -h, --help     : this screen
 -p, --no-page  : do not page list output
 -n,--name-only : only show "name" column in list output

Where command is one of the following or if omitted, equal to LIST.
 list       <filename> [section number]
            Shows contents of the archive's directory
 extract    <chm filename> <filename to extract> [saveasname]
            Extracts file "filename to get" from archive "filename",
            and, if specified, saves it to [saveasname]
 extractall <chm filename> [directory]
            Extracts all files from archive "filename" to directory
            "directory"
 unblockchm <filespec1> [filespec2] ..
            Mass unblocks (XPsp2+) the relevant CHMs. Multiple files
            and wildcards allowed
 extractalias <chmfilename> [basefilename] [symbolprefix]
            Extracts context info from file "chmfilename"
            to a "basefilename".h and "basefilename".ali,
            using symbols "symbolprefix"contextnr
 extracttoc <chmfilename> [filename]
            Extracts the toc (mainly to check binary TOC)
 extractindex <chmfilename> [filename]
            Extracts the index (mainly to check binary index)

这可能是一个开始,因为至少您会知道哪些页面是使用 ID 导出的,并且 URL 名称可能会提供一些信息。

该实用程序在最近的版本中(确保您获得 2.6.0)并且在 Free Pascal 源代码中也可用,它应该可以通过相对较小的努力转换为 Delphi。

基本上,chmls 工具是由各种测试代码库创建的。测试程序反编译和打印不同 CHM 部分的内容,并在创建帮助文件编译器 chmcmd 时使用,它也是 FPC 的一部分。

于 2012-11-08T18:49:01.403 回答
2

在 Delphi 中,调用帮助文件相当容易。在任何 VCL Forms 应用程序中,您HelpContext几乎可以将任何控件的属性设置为唯一的上下文 ID,它对应于帮助文件中的特定主题。帮助文件是使用这些映射编译的,但是当您反编译它时,这些映射不再存在。您必须有权访问原始帮助文件项目才能知道这些 ID。

  1. HelpContext帮助文件中对应上下文 ID 的控件集
  2. 使用IDHelpType的控件集htContextHelpContext
  3. 分配Application.HelpFile给 CHM 文件的适当位置
  4. 在应用程序中按F1任意位置时,帮助文件将根据控件或其父控件上的帮助上下文 ID 打开

如果您没有原始项目,并且您不想重新创建它,那么您将有一项很长的任务是遍历帮助文件的上下文 ID。尝试调用从 0 到 1,000 或可能 50,000 的帮助文件,具体取决于它的大小。

我实施的一种做法是在一个名为的指定单元中的一组常量,该单元HelpConstants.pas在我们的公共应用程序库中共享。每个常量名称都唯一且简要地描述了它所代表的主题。在启动应用程序时,我将这些上下文 ID 动态分配给它们相应的控件(通常是表单),而 VCL 会负责其余的工作。

于 2012-11-08T03:01:55.063 回答
1

我从 https://github.com/alrieckert/freepascal_arm/blob/master/packages/chm/bin/i386-win32/chmls.exe获得了 Marco 建议的实用程序 (通过选择 View Raw 下载)。我能够从 .chm 帮助文件中提取所有上下文标签,并通过调用 Application->HelpJump() 将我感兴趣的标签添加到我的 C++ Builder 程序中。高温高压

于 2013-09-16T15:07:16.973 回答