1

Using C++ Builder 10 Seattle (CX10).

I have a .chm with map IDs for certain topics. I can load the topics into an external window like this:

#include "Vcl.HTMLHelpViewer.hpp"

#pragma link "Vcl.HTMLHelpViewer"

// In the main form constructor:
Application->HelpFile = ExtractFilePath(Application->ExeName) + "MyHelp.chm";

// In button click event handler:
Application->HelpContext(10001);

This is great for many situations, but sometimes I want to embed the context-specific help within my TForm, such as on a TPanel. I found pieces of information about using WinAPI functions FindWindow and SetParent. So I tried this:

HWND t_hwnd = FindWindow(NULL, "My Help File");
if (t_hwnd)
{
    // HelpPanel is a TPanel with no properties adjusted from default
    ::SetParent(t_hwnd, HelpPanel->Handle);
}

Which compiles, links, runs and doesn't crash... but the subsequent call to Application->HelpContext(10001) still displays the topic in the external window, and not in the HelpPanel.

I am guessing that the easy-to-use Application->HelpContext call isn't what I need for redirecting to a VCL control, but I don't know where to look next.

Following up on the comments, here is where I am: I found out the ilink32 error (see my comment, below) was because I need to load HHCTRL.ocx in order to make a call to HtmlHelpA. So here is my test project code, a form with a TRadioGroup and TPanel. Only one radio button attempts to place the topic on the TPanel; the rest use Application->HelpContext. All of this compiles, links and runs, but the call to place the help on TPanel doesn't do anything visible.

Really hoping somebody can help... thanks.

// MainFrm.dfm
object MainForm: TMainForm
  Left = 0
  Top = 0
  Caption = 'MainForm'
  ClientHeight = 486
  ClientWidth = 686
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object FunctionsRadioGroup: TRadioGroup
    Left = 8
    Top = 8
    Width = 185
    Height = 105
    Caption = 'EDITS Language Functions'
    Items.Strings = (
      'LOOKUP'
      'RLOOKUP'
      'ILOOKUP'
      'STRCPY')
    TabOrder = 0
    OnClick = FunctionsRadioGroupClick
  end
  object HelpPanel: TPanel
    Left = 199
    Top = 8
    Width = 490
    Height = 477
    Caption = 'HelpPanel'
    TabOrder = 1
  end
end

// MainFrm.h
#ifndef MainFrmH
#define MainFrmH
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ExtCtrls.hpp>
//---------------------------------------------------------------------------

typedef HWND (WINAPI *FPHH) (HWND, LPCSTR, UINT,  DWORD);

// Map IDs in my CHM
#define LANG_FUNC_LOOKUP    10001
#define LANG_FUNC_RLOOKUP   10002
#define LANG_FUNC_STRCPY    10004
#define LANG_FUNC_ILOOKUP   10003

class TMainForm : public TForm
{
__published:    // IDE-managed Components
    TRadioGroup *FunctionsRadioGroup;
    TPanel *HelpPanel;
    void __fastcall FunctionsRadioGroupClick(TObject *Sender);
private:    // User declarations
    HINSTANCE FHHCTRL_OCX_INST;
    FPHH htmlHelp;

    bool __fastcall load_HHCTRL_OCX();

public:        // User declarations
    __fastcall TMainForm(TComponent* Owner);
    __fastcall ~TMainForm();

    void __fastcall DoShowEmbeddedHelp(TPanel* ThePanel, NativeInt TheTopicID);
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif

// MainFrm.cpp
#include <vcl.h>
#pragma hdrstop

#include "MainFrm.h"
#include <Vcl.HTMLHelpViewer.hpp>
#include <HtmlHelp.h>

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Vcl.HTMLHelpViewer"
//#pragma link "htmlhelp.lib"
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
    : TForm(Owner)
{
    Application->HelpFile = ExtractFilePath(Application->ExeName) +
        "MyHelpFile.chm";

    FHHCTRL_OCX_INST = 0;

} // ctor
//---------------------------------------------------------------------------
__fastcall TMainForm::~TMainForm()
{
    if (FHHCTRL_OCX_INST > 0)
    {
        FreeLibrary(FHHCTRL_OCX_INST);
    }
}// dtor
//---------------------------------------------------------------------------
void __fastcall TMainForm::FunctionsRadioGroupClick(TObject *Sender)
{
    TRadioGroup* t_radio = dynamic_cast<TRadioGroup*>(Sender);

    if (t_radio)
    {

        switch (t_radio->ItemIndex)
        {
            case 0:
                //Application->HelpContext(LANG_FUNC_LOOKUP);
                DoShowEmbeddedHelp(HelpPanel, LANG_FUNC_LOOKUP);
                break;

            case 1:
                Application->HelpContext(LANG_FUNC_RLOOKUP);
                break;

            case 2:
                Application->HelpContext(LANG_FUNC_ILOOKUP);
                break;

            case 3:
                Application->HelpContext(LANG_FUNC_STRCPY);
                break;

        }
    }
}
//---------------------------------------------------------------------------
bool __fastcall TMainForm::load_HHCTRL_OCX()
{
    bool t_is_loaded = (FHHCTRL_OCX_INST > 0);
    if (!t_is_loaded)
    {
        FHHCTRL_OCX_INST = LoadLibrary("HHCTRL.OCX");
        if (FHHCTRL_OCX_INST > 0)
        {
            (FARPROC&) htmlHelp = GetProcAddress(FHHCTRL_OCX_INST, "HtmlHelpA");
            if (htmlHelp)
            {
                t_is_loaded = true;
            }
        }
    }

    return t_is_loaded;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::DoShowEmbeddedHelp(TPanel* ThePanel, NativeInt TheTopicID)
{
    HH_WINTYPE wintypedef;
    AnsiString t_helpfile = ExtractFilePath(Application->ExeName) + "MyHelpFile.chm";
    AnsiString TheWinName = "HelpPanel";

    if (!FileExists(t_helpfile))
    {
        MessageDlg(AnsiString("Help file not found: ") + t_helpfile,
            mtError, TMsgDlgButtons() << mbOK, 0);
        return;
    }

    // Zero the structure
    memset(&wintypedef, 0, sizeof(HH_WINTYPE));
    // Prepare the properties
    wintypedef.cbStruct = sizeof(wintypedef);
    wintypedef.fUniCodeStrings = false;
    wintypedef.pszType = TheWinName.c_str();
    wintypedef.fsValidMembers =
            HHWIN_PARAM_PROPERTIES |
            HHWIN_PARAM_STYLES |
            HHWIN_PARAM_EXSTYLES |
            HHWIN_PARAM_RECT |
            HHWIN_PARAM_NAV_WIDTH |
            HHWIN_PARAM_SHOWSTATE |
            HHWIN_PARAM_TB_FLAGS |
            HHWIN_PARAM_EXPANSION;

    wintypedef.fsWinProperties =
            HHWIN_PROP_NOTITLEBAR |
            HHWIN_PROP_NO_TOOLBAR |
            HHWIN_PROP_NODEF_STYLES |
            HHWIN_PROP_NODEF_EXSTYLES |
            HHWIN_PROP_TRI_PANE;

    wintypedef.pszCaption = "";
    wintypedef.dwStyles = WS_VISIBLE | WS_CHILDWINDOW;
    wintypedef.dwExStyles = WS_EX_LEFT;
    wintypedef.rcWindowPos =
        Rect(0, 0, ThePanel->ClientWidth, ThePanel->ClientHeight);

    wintypedef.nShowState = SW_SHOW;
    wintypedef.fsToolBarFlags = HHWIN_BUTTON_PRINT | HHWIN_BUTTON_BACK ;
    wintypedef.fNotExpanded = true;

    if (load_HHCTRL_OCX())
    {
        if ((int)htmlHelp(0, NULL, HH_SET_WIN_TYPE, (DWORD)&wintypedef) < 0)
        {
            ShowMessage("Help failed on topic");
        }
        else
        {
            /* NOTE: This was close, but wrong. 
            int HelpWinHandle =
                (int)htmlHelp(ThePanel->Handle, "HelpPanel", HH_HELP_CONTEXT, TheTopicID);
             */

            AnsiString t_fn = t_helpfile + AnsiString(">HelpPanel");
            int HelpWinHandle =
               (int)htmlHelp(ThePanel->Handle, t_fn.c_str(), HH_HELP_CONTEXT, TheTopicID);


        }


    }
} // DoShowEmbeddedHelp
//---------------------------------------------------------------------------
4

2 回答 2

0

好吧,我终于想通了。

在我为函数TMainForm::DoShowEmbeddedHelp发布的代码中,我没有正确准备 HtmlHelpA 的第二个参数。应该是这样的:

AnsiString t_fn = t_helpfile + AnsiString(">HelpPanel");
HelpWinHandle =
    (int)htmlHelp(ThePanel->Handle, t_fn.c_str(), HH_HELP_CONTEXT, TheTopicID);

现在我得到了我想要的结果。

于 2016-01-21T18:49:20.843 回答
0

这深入到了 HTMLHelp API(20 年前由 Ralph Walden 用 C++ 编写)。你可能会警告...

我有帮助创作经验,而且我不是 C++ 程序员。因此,HTMLHelp Viewer hh.exe 是 Internet Explorer API 的包装器,在右侧的内容窗格中显示了 CHM 的 HTML 主题。

你知道“应用程序->HelpContext(10001);” 总是使用指定的 topicId“10001”调用帮助查看器。嵌入式帮助的使用较少,如今也不是用户想要的。当然,第二个帮助窗口更容易。

一些想法和技巧,例如缩小由帮助作者(CHM 文件的创建者)完成的查看器,您将在以下位置看到: Microsoft HTML Help - Get the topic page URL from the topic ID

更多信息 - 对不起 Delphi - 您可以在以下位置找到: 如何在 delphi windows/vcl 应用程序中控制/删除嵌入式 chm 帮助文件的边框?

高温高压

于 2016-01-21T13:28:42.383 回答