Open the .chm file on a specific page / topic with command line arguments

I am trying to open a .chm file (Windows help file) on a specific page / topic using a system call in C ++.

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

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

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

+8
source share
4 answers

Well, the arguments are as follows:

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

The Windows SDK has an API called HtmlHelp in the HtmlHelp.h file. You can call like this:

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

Microsoft Docs Feature - HtmlHelpA provides additional information about the feature. HtmlHelp() usually resolved in HtmlHelpA() or HtmlHelpW() depending on whether the Unicode compiler option is set or not.

See also Microsoft Docs - Overview of the HTML Help API .

+4
source

Another option is to use ShellExecute. Microsoft help is not easy to use. This approach is much simpler and fits your question. The following is a brief procedure for opening a help file and transmitting an identification number. I just created some simple char s so you can see what happens:

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

Themes are numbered in your .chm file. I installed #define for each topic, so if I had to change the .chm file, I could just change the included file to match and not worry about searching the code for hardcoded values.

+2
source

The same also works for creating a Windows shortcut that opens a specific page. Use this as the "target" command line:

C: \ Windows \ hh.exe ms-its: [file_name .chm] :: [page_name .htm]

If you don't know [page_name]: From the chm help viewer, try printing the landing page on a virtual printer such as PdfCreator. The automatically generated output file name is likely to contain [page_mane].

Thanks to sazr for the initial syntax!

0
source

All Articles