8

C++ のシステム コールを使用して、特定のページ/トピックで .chm ファイル (Windows ヘルプ ファイル) を開こうとしています。

次のコードを使用して .chm ファイルを開始ページに正常に開くことができますが、ヘルプ ファイル内の特定のページ/トピックに .chm ファイルを開くにはどうすればよいですか?

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

PS:システムが悪/落胆していることは知っていますが、システム部分は、.chmファイル(開きたいページを指定する)で渡すコマンドライン引数とはあまり関係がありません。

4

3 に答える 3

5

Windows SDK には、HtmlHelp.h ファイルに HtmlHelp とい​​う API があります。次のように呼び出すことができます。

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

Microsoft Docs - HtmlHelpA 関数は、関数に関する詳細情報を提供します。HtmlHelp()通常、Unicode コンパイラ オプションが設定されているかどうかに応じてHtmlHelpA()解決されます。HtmlHelpW()

Microsoft Docs - HTML Help API の概要も参照してください。

于 2012-06-18T04:53:15.310 に答える
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 ファイルを変更する必要がある場合は、一致するようにインクルード ファイルを変更するだけで済み、ハードコーディングされた値をコードで検索することを心配する必要はありません。

于 2014-07-18T20:21:31.163 に答える