繁体   English   中英

Delphi HtmlHelpAPI-如何将CHM文件定向到不同的部分

[英]Delphi HtmlHelpAPI- How to direct a CHM file to open to different sections

我可以通过传递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


GetHelp过程

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并未记录在程序中或未映射。

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的一部分)时使用了该程序。

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

  1. 将控件的HelpContext设置为帮助文件中的相应上下文ID
  2. 将控件的HelpType设置为htContext以使用HelpContext ID
  3. Application.HelpFile分配到CHM文件的适当位置
  4. 在应用程序中的任何位置按F1 ,将基于控件或其父控件上的“帮助上下文ID”打开帮助文件。

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM