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

问题描述 投票:6回答:3

我试图通过在C ++中使用系统调用在特定页面/主题上打开.chm文件(Windows帮助文件)。

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

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

PS:我知道系统是邪恶的/不鼓励的,但系统部分与我传递的.chm文件(它将指定我要打开的页面)的命令行参数并不真正相关,我试图确定。

c++ chm view-helpers
3个回答
4
投票

好的参数是这样的:

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

4
投票

Windows SDK中的API在HtmlHelp.h文件中名为HtmlHelp。你可以像这样打电话:

HtmlHelp(GetDesktopWindow(), L"C:\\helpfile\\::/helptopic.html", HH_DISPLAY_TOPIC, NULL);

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

另见Microsoft Docs - HTML Help API Overview


2
投票

另一个选择 - 使用ShellExecute。 Microsoft的帮助不容易使用。这种方法更容易,符合您的问题。这是打开帮助文件并传递ID号的快速例程。我刚刚设置了一些简单的char,所以你可以看到发生了什么:

    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文件,我可以更改包含文件以匹配,而不必担心在代码中搜索硬编码值。

© www.soinside.com 2019 - 2024. All rights reserved.