Open .chm file at specific page/topic using command line arguments
Asked Answered
S

3

9

I am attempting to open a .chm file(A windows help file) at a specific page/topic by using a system call in C++.

I can successfully open the .chm file to the start page through the following code, but how can I open a .chm file to a specific page/topic inside the help file?

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

PS: I know system is evil/discouraged but the system part is not really relevant its the command line arguments I pass with the .chm file(that will specify what page I want to open) that I am trying to determine.

Spahi answered 18/6, 2012 at 4:32 Comment(1)
Take a look at this link: help-info.de/en/Help_Info_HTMLHelp/hh_command.htmNarcoanalysis
S
7

Ok the arguments are like so:

system(" /Q /E:ON /C HH.EXE ms-its:myChm.chm::myPageName.htm");
Spahi answered 19/7, 2014 at 0:58 Comment(1)
Thank you for posting this langauge-independent solution. In Python, subprocess.Popen("hh,exe ms-its:C:/path/x.chm::/dir/pg.html") works great and I will probably use it on Windows to display Idle help. I am curious whether you know what the /Q /E:ON /C flags are supposed to do.Akilahakili
C
6

There is an API in the Windows SDK called HtmlHelp in the HtmlHelp.h file. You can call like so:

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

The Microsoft Docs - HtmlHelpA function provides more information about the function. HtmlHelp() will normally resolve to HtmlHelpA() or HtmlHelpW() depending on whether Unicode compiler option is set or not.

See as well Microsoft Docs - HTML Help API Overview.

Cheops answered 18/6, 2012 at 4:53 Comment(0)
B
2

Another option - use ShellExecute. The Microsoft help is not easy to use. This approach is much easier and in line with your question. Here is a quick routine to open a help file and pass an ID number. I have just set up some simple char’s so you can see what is going on:

    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);
}

The topics are numbered within your .chm file. I set up a #define for each topic so if I had to change the .chm file I could just change the include file to match and not have to worry about searching through the code for hardcoded values.

Babylon answered 18/7, 2014 at 20:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.