简体   繁体   English

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

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

I am able to open a CHM file by passing a ShortInteger and casting it as a Word for the dwData parameter. 我可以通过传递ShortInteger并将其强制转换为dwData参数的Word来打开CHM文件。 IE 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..


Call get help pass my ID 致电获取帮助以传递我的ID

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


GetHelp procedure GetHelp过程

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


HtmlHelpW function HtmlHelpW函数

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

As I pass different ShortIntegers I am able to initialize the help file at different sections. 当我传递不同的ShortIntegers时,我可以在不同的部分初始化帮助文件。 However I can't figure out how the values are mapped. 但是我不知道如何映射值。 There are some sections in the chm file that I want to be able to map to but the short Integer or context ID associated with them is not documented in the program or is not mapped. 我希望能够映射到chm文件中的某些部分,但是与它们相关联的短整数或上下文ID并未记录在程序中或未映射。

Free Pascal comes with a chmls.exe util that has a command that tries to recover the alias (context) data: 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)

This might be a start, since at least you'll know which pages are exported using an ID, and maybe the URL names will give some information. 这可能是一个开始,因为至少您会知道使用ID导出了哪些页面,并且URL名称可能会提供一些信息。

The util is in recent releases (make sure you get 2.6.0) and also available in Free Pascal source, which should be convertable to Delphi with relatively minor effort. 该实用程序在最新发行版中(请确保您获得2.6.0版),并且还可以在Free Pascal源代码中使用,该源代码应该可以通过较小的工作量即可转换为Delphi。

Basically the chmls tool was created out of various test codebases. 基本上,chmls工具是根据各种测试代码库创建的。 The testprograms decompiled and printed contents of different CHM sections and were used while creating the helpfile compiler, chmcmd, which is also part of FPC. 测试程序反编译并打印了不同CHM部分的内容,并在创建帮助文件编译器chmcmd(也是FPC的一部分)时使用了该程序。

In Delphi, calling a help file is rather easy. 在Delphi中,调用帮助文件非常容易。 In any VCL Forms application, you can set the HelpContext property of almost any control to a unique Context ID, which corresponds to a particular topic in the Help File. 在任何VCL Forms应用程序中,几乎可以将任何控件的HelpContext属性设置为唯一的上下文ID,该ID与帮助文件中的特定主题相对应。 The Help File was compiled with these mappings, but when you decompile it, these mappings are no longer there. 帮助文件是使用这些映射进行编译的,但是当您对其进行反编译时,这些映射将不再存在。 You must have access to the original help file project in order to know these ID's. 您必须有权访问原始帮助文件项目才能知道这些ID。

  1. Set HelpContext of controls to the corresponding Context ID in the Help File 将控件的HelpContext设置为帮助文件中的相应上下文ID
  2. Set HelpType of controls to htContext to use the HelpContext ID 将控件的HelpType设置为htContext以使用HelpContext ID
  3. Assign Application.HelpFile to the appropriate location of the CHM file Application.HelpFile分配到CHM文件的适当位置
  4. When pressing F1 anywhere in your application, the help file will open based on the Help Context ID on the control, or its parent control 在应用程序中的任何位置按F1 ,将基于控件或其父控件上的“帮助上下文ID”打开帮助文件。

If you don't have the original project, and you don't want to re-create it, then you would have a long task of iterating through the Context ID's of your help file. 如果您没有原始项目,并且不想重新创建它,那么您将有一个漫长的任务,即遍历帮助文件的Context ID。 Try to call the help file starting from 0 through 1,000 or possibly 50,000, depending on the size of it. 尝试从0到1,000或可能是50,000的范围内调用帮助文件,具体取决于文件的大小。

A practice I implement is a set of constants in a designated unit called HelpConstants.pas which is shared across our common application base. 我实现的一种做法是在一个称为HelpConstants.pas的指定单元中的一组常量,这些常量在我们通用的应用程序库中共享。 Each constant name uniquely and briefly describes the topic which it represents. 每个常数名称都唯一且简短地描述了它代表的主题。 Upon starting the application, I dynamically assign these Context ID's to their corresponding controls (usually forms) and VCL takes care of the rest. 启动应用程序后,我将这些上下文ID动态分配给它们相应的控件(通常是表格),而VCL负责其余的工作。

I got the utility Marco suggested from https://github.com/alrieckert/freepascal_arm/blob/master/packages/chm/bin/i386-win32/chmls.exe (download by selecting View Raw). 我从https://github.com/alrieckert/freepascal_arm/blob/master/packages/chm/bin/i386-win32/chmls.exe (建议通过选择View Raw下载)获得Marco建议的实用程序。 I was able to extract all the context tags from the .chm help file and add the one I was interested in to my C++ Builder program by calling Application->HelpJump(). 我能够从.chm帮助文件中提取所有上下文标记,并通过调用Application-> HelpJump()将我感兴趣的标记添加到C ++ Builder程序中。 HTH 高温超导

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

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