使用命令行参数在特定页面/主题打开.chm文件

9

我正在尝试使用C++中的系统调用打开一个.chm文件(Windows帮助文件)到特定页面/主题。

我可以通过以下代码成功打开.chm文件到起始页,但是如何打开.chm文件到帮助文件内的特定页面/主题?

system("start c:/help/myhelp.chm");

PS:我知道系统很邪恶/不被鼓励,但是系统部分不是真正相关的内容,而是我传递给.chm文件的命令行参数(这将指定我要打开的页面),我正在尝试确定它们。


3
请查看此链接:http://www.help-info.de/en/Help_Info_HTMLHelp/hh_command.htm。 - Naveen
3个回答

7

好的,参数如下:

system(" /Q /E:ON /C HH.EXE ms-its:myChm.chm::myPageName.htm");

1
感谢您发布这个与语言无关的解决方案。在Python中,subprocess.Popen("hh,exe ms-its:C:/path/x.chm::/dir/pg.html")非常好用,我可能会在Windows上使用它来显示Idle帮助。我很好奇您是否知道/Q /E:ON /C标志应该做什么。 - Terry Jan Reedy

6
在Windows SDK中有一个名为HtmlHelp的API,其位于HtmlHelp.h文件中。您可以这样调用:
HtmlHelp(GetDesktopWindow(), L"C:\\helpfile\\::/helptopic.html", HH_DISPLAY_TOPIC, NULL);

Microsoft Docs - HtmlHelpA函数提供了有关该函数的更多信息。HtmlHelp()通常会解析为HtmlHelpA()HtmlHelpW(),具体取决于是否设置了Unicode编译器选项。

另请参见Microsoft Docs - HTML帮助API概述


2

另一种选择是使用ShellExecute。Microsoft的帮助文档不易使用。这种方法更容易理解,与您的问题相符。下面是一个快速的例程,用于打开帮助文件并传递ID号码。我只设置了一些简单的字符,以便您可以看到正在发生什么:

    void DisplayHelpTopic(int Topic)
{

    // The .chm file usually has the same name as the application - if you don’t want to hardcode it...
    char *CmndLine = GetCommandLine(); // Gets the command the program started with.
    char Dir[255];
    GetCurrentDirectory (255, Dir);
    char str1[75] = "\0"; // Work string
    strncat(str1, CmndLine, (strstr(CmndLine, ".exe") - CmndLine)); // Pull out the first parameter in the command line (should be the executable name) w/out the .exe
    char AppName[50] = "\0";
    strcpy(AppName, strrchr(str1, '\\')); // Get just the name of the executable, keeping the '\' in front for later when it is appended to the directory

    char parms[300];
    // Build the parameter string which includes the topic number and the fully qualified .chm application name
    sprintf(parms,_T("-mapid %d ms-its:%s%s.chm"), Topic, Dir, AppName);
    // Shell out, using My Window handle, specifying the Microsoft help utility, hh.exe, as the 'noun' and passing the parameter string we build above
// NOTE: The full command string will look like this:
//   hh.exe -mapid 0 ms-its:C:\\Programs\\Application\\HelpFile.chm
    HINSTANCE retval = ShellExecute(MyHndl, _T("open"), _T("hh.exe"), parms, NULL, SW_SHOW);
}

这些主题在你的.chm文件中是有编号的。我为每个主题设置了一个#define,所以如果我需要更改.chm文件,我只需更改包含文件以匹配,而不必担心在代码中搜索硬编码值。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接