重复使用通过 hh.exe 打开的帮助 window

Reusing a Help window opened via hh.exe

我通过 shell 执行 hh.exe 从 Lua 中打开一个 .chm 帮助文件命令;用户单击 Lua 应用程序中的多个帮助按钮之一,并被定向到帮助文件中的一个主题,该主题取决于所使用的帮助按钮的上下文。

local HelpFile = strDir.."\"..strName.." "..strVersion..".chm"
--strDir ,strName, strVersion all identify the help file to be used
local topicpath = "options" --an example; will differ according to application context
local helpexecutable = "C:\windows\hh.exe"
local helpparms = "::/"..string.lower(string.gsub(topicpath..".htm", "")
local bOK, intErrorCode, strErrortext = 
    fhShellExecute(helpexecutable, HelpFile..helpparms)
    -- open the help file at a specified location

此代码可以很好地打开我想要的主题的帮助文件。

注意 fhShellExecute 是程序宿主特定的 API,相当于 os.execute

PARAMETERS:

strFileName: string: the full path to the file. Remember that slashes in Lua must be doubled (e.g "C:\MyDocuments\My Program.exe").

strParams: string: parameters. If strFileName is an executable file, strParams holds the parameters to be passed to it. Should be empty, or not supplied, if strFileName is a document file.

strDirectory: string: specifies the default (working) directory for the action. If not supplied, the current working directory is used.

strOperation: string: specifies the action to be performed. The set of available actions depends on the particular file or folder. Generally, the actions available from an object's shortcut menu are available actions.

iShowCmd: integer: Specifies how an application is to be displayed when it is opened. If not supplied, the value defaults to 1. The following values are defined:

0 Hides the window and activates another window

1 Activates and displays a window. If the window is minimized or maximized, Windows restores it toits original size and position. An application should specify this flag when displaying the window forthe first time.

2 Activates the window and displays it as a minimized window.

3 Activates the window and displays it as a maximized window.

4 Displays a window in its most recent size and position. The active window remains active.

5 Activates the window and displays it in its current size and position.

6 Minimizes the specified window and activates the next top-level window in the Z order.

7 Displays the window as a minimized window. The active window remains active.

8 Displays the window in its current state. The active window remains active.

9 Activates and displays the window. If the window is minimized or maximized, Windows restores it toits original size and position. An application should specify this flag when restoring a minimizedwindow.

因为我正在使用 hh.exe,每次用户单击“帮助”按钮时都会出现一个新的“帮助”实例,这不是我(或用户)想要的。打开帮助 window 来阻止应用程序的运行是不可接受的。

采用此处显示的方法 (测试帮助文件是否可重命名——如果不可重命名,则说明它正在使用中)我可以防止打开第二个帮助 window。但是,我看不到任何指示打开的帮助 window 导航到新上下文主题的方法。

我可以访问非常有限的一组 Lua 库,因此我需要一个可以通过 shell 命令执行的解决方案。我的想法是:

但我不知道如何做这两件事。

现阶段我还没有在Windows10版本1903的机器上安装LUA开发环境。因此,我使用 PowerShell 示例描述了答案,并提供了 LUA 的一些提示。转换应该没有问题。

正如我之前提到的,KeyHH.exe 是一个增强 HTML 帮助的程序。它可以作为 HH.EXE 的补充或完全替代。 KeyHH 提供 HH.EXE 的所有功能,在 HTML 帮助中提供一些已知错误的解决方案,还提供其他功能。

但是,请注意,这确实是很久以前的事了(大约 12 年),对于今天的 Windows 操作系统,您可能需要在这里得到警告。但我很惊讶它在我的机器上运行。

旧网站 keyworks.net 不再可用。作为退休的 Microsoft Help MVP,我们几年前将内容复制到 http://keyworks.helpmvp.com.

所以,还是试一试吧。我建议先按照以下步骤操作,然后在 LUA 中根据您的需要进行调整。如我所见,没有经验

  • 下载Keyhh.zip
  • 解压缩 KeyHH.exe 到临时文件夹,例如D:/_working
  • 将 KeyHH.exe 剪切并粘贴到 C:/Windows,其中 hh.exe 也位于其中(具有管理员权限)
  • 从我的站点下载示例 CHM file 到临时文件夹,例如D:/_working。要打开此 CHM 文件,请右键单击已保存的文件,单击“属性”,然后单击“取消阻止”。这仅用于测试用例(见下文)。

使用 PowerShell 执行以下 hh.exe 命令:

hh.exe D:/_working/CHM-example.chm
hh.exe D:/_working/CHM-example.chm::/Garden/flowers.htm
hh.exe D:/_working/CHM-example.chm::/Garden/tree.htm
hh.exe -mapid 10010 D:/_working/CHM-example.chm 

你知道这导致了四个帮助windows:

您可以使用 KeyHH 创建独立的 HTML 帮助 window。此 window 保持打开状态,直到用户将其关闭。创建此 window 后,您可以在 window 中打开新主题,而无需创建新的 window,就像使用 WinHelp 一样。您可以从 HTML 帮助 window、程序或 WinHelp 文件中使用此功能。

您通过指定破折号 (-) 后跟标识名称和 CHM 文件的名称来创建唯一的 KeyHH window。然后 KeyHH 将检查是否已打开使用此标识名称的 HTML 帮助 window。如果是这样,HTML 帮助 window 将简单地更新为新的 CHM 文件或主题。如果未打开,KeyHH 将创建一个新的 HTML 帮助 window.

您可以使用任何您想要的标识符,只要第一个字符不以井号 (#) 字符开头。

在上面的示例中,要在 CHM-example.chm 文件中打开名为 flowers.htm 的主题,您可以使用此命令:

KeyHH.exe -MyID D:/_working/CHM-example.chm::/Garden/flowers.htm

假设您随后想打开另一个名为 tree.htm 的主题,您将使用此命令:

KeyHH.exe -MyID D:/_working/CHM-example.chm::/Garden/tree.htm

或 mapid 的另一个主题

KeyHH.exe -MyID -#mapid 10010 D:/_working/CHM-example.chm   

所有这些命令只产生一个帮助 window:

请注意,在使用 KeyHH 时出现警告不要使用带连字符的文件名(例如,new-topic.htm)。。您可能需要重命名您的文件。

我想你只需要调整几行代码:

local KeyHHParam = " -MyID "
local HelpFile = strDir.."\"..strName.." "..strVersion..".chm"
local topicpath = "options" 
local helpexecutable = "C:\windows\KeyHH.exe"
local helpparms = "::/"..string.lower(string.gsub(topicpath..".htm", "")
local bOK, intErrorCode, strErrortext = 
    fhShellExecute(helpexecutable, KeyHHParam..HelpFile..helpparms)