使用C ++ Builder 10 Seattle(CX10)。
我有一个.chm,其中包含某些主题的地图ID。我可以将主题加载到这样的外部窗口中:
#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);
这在很多情况下都很棒,但有时我想在我的TForm中嵌入特定于上下文的帮助,例如在TPanel上。我找到了有关使用WinAPI函数FindWindow和SetParent的信息。所以我尝试了这个:
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);
}
编译,链接,运行并且不会崩溃...但是后续调用Application-> HelpContext(10001)仍会在外部窗口中显示主题,而不是在HelpPanel中。
我猜这个易于使用的Application-> HelpContext调用不是重定向到VCL控件所需要的,但我不知道接下来要去哪里看。
跟进评论,这就是我的位置:我发现ilink32错误(请参阅下面的评论)是因为我需要加载HHCTRL.ocx才能拨打电话到HtmlHelpA。所以这是我的测试项目代码,一个带有TRadioGroup和TPanel的表单。只有一个单选按钮试图将主题放在TPanel上;其余使用Application-> HelpContext。所有这些都是编译,链接和运行,但是将帮助放在TPanel上的调用并没有做任何可见的事情。
真的希望有人能帮忙......谢谢。
// 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
//---------------------------------------------------------------------------
答案 0 :(得分:0)
这深入到HTMLHelp API(20年前由Ralph Walden用C ++编写)。你可能会警告......
我有帮助创作经验,而且我不是C ++程序员。因此,HTMLHelp Viewer hh.exe是Internet Explorer API的包装器,在右侧的内容窗格中显示了CHM的HTML主题。
你知道&#34; Application-&gt; HelpContext(10001);&#34;正在使用指定的topicId&#34; 10001&#34;调用帮助查看器总是。嵌入式帮助的使用较少,而今天并不是用户想要的。当然,第二个帮助窗口更容易。
一些想法和技巧,例如缩小查看者的帮助作者(CHM文件的创建者)所做的观察,你会看到: Microsoft HTML Help - Get the topic page URL from the topic ID
更多信息 - 对不起德尔福 - 你会发现: How to control/remove borders of embedded chm help file in delphi windows/vcl application?
HTH
答案 1 :(得分:0)
好吧,我终于明白了。
在我为功能 TMainForm :: DoShowEmbeddedHelp 发布的代码中,我没有正确准备第二个参数到HtmlHelpA。它应该是这样的:
AnsiString t_fn = t_helpfile + AnsiString(">HelpPanel");
HelpWinHandle =
(int)htmlHelp(ThePanel->Handle, t_fn.c_str(), HH_HELP_CONTEXT, TheTopicID);
现在我得到了我想要的结果。