const HH_DISPLAY_TOPIC = $0000; {$EXTERNALSYM HH_DISPLAY_TOPIC} HH_HELP_FINDER = $0000; // WinHelp equivalent {$EXTERNALSYM HH_HELP_FINDER} HH_DISPLAY_TOC = $0001; // not currently implemented {$EXTERNALSYM HH_DISPLAY_TOC} HH_DISPLAY_INDEX = $0002; // not currently implemented {$EXTERNALSYM HH_DISPLAY_INDEX} HH_DISPLAY_SEARCH = $0003; // not currently implemented {$EXTERNALSYM HH_DISPLAY_SEARCH} HH_SET_WIN_TYPE = $0004; {$EXTERNALSYM HH_SET_WIN_TYPE} HH_GET_WIN_TYPE = $0005; {$EXTERNALSYM HH_GET_WIN_TYPE} HH_GET_WIN_HANDLE = $0006; {$EXTERNALSYM HH_GET_WIN_HANDLE} HH_ENUM_INFO_TYPE = $0007; // Get Info type name, call repeatedly to enumerate, -1 at end {$EXTERNALSYM HH_ENUM_INFO_TYPE} HH_SET_INFO_TYPE = $0008; // Add Info type to filter. {$EXTERNALSYM HH_SET_INFO_TYPE} HH_SYNC = $0009; {$EXTERNALSYM HH_SYNC} {$IFDEF HTMLHELP11} HH_ADD_NAV_UI = $000A; // not currently implemented {$EXTERNALSYM HH_ADD_NAV_UI} HH_ADD_BUTTON = $000B; // not currently implemented {$EXTERNALSYM HH_ADD_BUTTON} HH_GETBROWSER_APP = $000C; // not currently implemented {$EXTERNALSYM HH_GETBROWSER_APP} {$ENDIF} {$IFDEF HTMLHELP12} HH_RESERVED1 = $000A; {$EXTERNALSYM HH_RESERVED1} HH_RESERVED2 = $000B; {$EXTERNALSYM HH_RESERVED2} HH_RESERVED3 = $000C; {$EXTERNALSYM HH_RESERVED3} {$ENDIF} HH_KEYWORD_LOOKUP = $000D; {$EXTERNALSYM HH_KEYWORD_LOOKUP} HH_DISPLAY_TEXT_POPUP = $000E; // display string resource id or text in a popup window {$EXTERNALSYM HH_DISPLAY_TEXT_POPUP} HH_HELP_CONTEXT = $000F; // display mapped numeric value in dwData {$EXTERNALSYM HH_HELP_CONTEXT} HH_TP_HELP_CONTEXTMENU = $0010; // text popup help, same as WinHelp HELP_CONTEXTMENU {$EXTERNALSYM HH_TP_HELP_CONTEXTMENU} HH_TP_HELP_WM_HELP = $0011; // text popup help, same as WinHelp HELP_WM_HELP {$EXTERNALSYM HH_TP_HELP_WM_HELP} HH_CLOSE_ALL = $0012; // close all windows opened directly or indirectly by the caller {$EXTERNALSYM HH_CLOSE_ALL} HH_ALINK_LOOKUP = $0013; // ALink version of HH_KEYWORD_LOOKUP {$EXTERNALSYM HH_ALINK_LOOKUP} HH_GET_LAST_ERROR = $0014; // not currently implemented, See HHERROR.h {$EXTERNALSYM HH_GET_LAST_ERROR} HH_ENUM_CATEGORY = $0015; // Get category name, call repeatedly to enumerate, -1 at end {$EXTERNALSYM HH_ENUM_CATEGORY} HH_ENUM_CATEGORY_IT = $0016; // Get category info type members, call repeatedly to enumerate, -1 at end {$EXTERNALSYM HH_ENUM_CATEGORY_IT} HH_RESET_IT_FILTER = $0017; // Clear the info type filter of all info types. {$EXTERNALSYM HH_RESET_IT_FILTER} HH_SET_INCLUSIVE_FILTER = $0018; // set inclusive filtering method for untyped topics to be included in display {$EXTERNALSYM HH_SET_INCLUSIVE_FILTER} HH_SET_EXCLUSIVE_FILTER = $0019; // set exclusive filtering method for untyped topics to be excluded from display {$EXTERNALSYM HH_SET_EXCLUSIVE_FILTER} {$IFDEF HTMLHELP11} HH_SET_GUID = $001A; // For Microsoft Installer -- dwData is a pointer to the GUID string {$EXTERNALSYM HH_SET_GUID} {$ENDIF} {$IFDEF HTMLHELP12} HH_INITIALIZE = $001C; // Initializes the help system. {$EXTERNALSYM HH_INITIALIZE} HH_UNINITIALIZE = $001D; // Uninitializes the help system. {$EXTERNALSYM HH_UNINITIALIZE} HH_PRETRANSLATEMESSAGE = $00FD; // Pumps messages. (NULL, NULL, MSG*). {$EXTERNALSYM HH_PRETRANSLATEMESSAGE} HH_SET_GLOBAL_PROPERTY = $00FC; // Set a global property. (NULL, NULL, HH_GPROP) {$EXTERNALSYM HH_SET_GLOBAL_PROPERTY} {$ENDIF}
type PHHLastError = ^THHLastError; tagHH_LAST_ERROR = packed record cbStruct: Integer; // size of this structure hr: HRESULT; // the last error code. description: PWideChar; // a description of the error (unicode string - BSTR). end; THHLastError = tagHH_LAST_ERROR;
PHHPopup = ^THHPopup; tagHH_POPUP = packed record cbStruct: Integer; // sizeof this structure hinst: HINST; // instance handle for string resource idString: UINT; // string resource id, or text id if pszFile is specified in HtmlHelp call pszText: LPCTSTR; // used if idString is zero pt: TPoint; // top center of popup window clrForeGround: TColorRef; // use -1 for default clrBackground: TColorRef; // use -1 for default rcMargins: TRect; // amount of space between edges of window and text, -1 for each member to ignore pszFont: LPCTSTR; // facename, point size, char set, BOLD ITALIC UNDERLINE end; {$EXTERNALSYM tagHH_POPUP} HH_POPUP = tagHH_POPUP; {$EXTERNALSYM HH_POPUP} THHPopup = tagHH_POPUP;
PHHAKLink = ^THHAKLink; tagHH_AKLINK = packed record cbStruct: Integer; // sizeof this structure fReserved: BOOL; // must be FALSE (really!) pszKeywords: LPCTSTR; // semi-colon separated keywords pszUrl: LPCTSTR; // URL to jump to if no keywords found (may be NULL) pszMsgText: LPCTSTR; // Message text to display in MessageBox if pszUrl is NULL and no keyword match pszMsgTitle: LPCTSTR; // Message text to display in MessageBox if pszUrl is NULL and no keyword match pszWindow: LPCTSTR; // Window to display URL in fIndexOnFail: BOOL; // Displays index if keyword lookup fails. end; {$EXTERNALSYM tagHH_AKLINK} HH_AKLINK = tagHH_AKLINK; {$EXTERNALSYM HH_AKLINK} THHAKLink = tagHH_AKLINK;
type PHHEnumIT = ^THHEnumIT; tagHH_ENUM_IT = packed record cbStruct: Integer; // size of this structure iType: Integer; // the type of the information type ie. Inclusive, Exclusive, or Hidden pszCatName: LPCSTR; // Set to the name of the Category to enumerate the info types in a category; else NULL pszITName: LPCSTR; // volitile pointer to the name of the infotype. Allocated by call. Caller responsible for freeing pszITDescription: LPCSTR; // volitile pointer to the description of the infotype. end; {$EXTERNALSYM tagHH_ENUM_IT} HH_ENUM_IT = tagHH_ENUM_IT; {$EXTERNALSYM HH_ENUM_IT} PHH_ENUM_IT = ^tagHH_ENUM_IT; {$EXTERNALSYM PHH_ENUM_IT} THHEnumIT = tagHH_ENUM_IT;
PHHEnumCat = ^THHEnumCat; tagHH_ENUM_CAT = packed record cbStruct: Integer; // size of this structure pszCatName: LPCSTR; // volitile pointer to the category name pszCatDescription: LPCSTR; // volitile pointer to the category description end; {$EXTERNALSYM tagHH_ENUM_CAT} HH_ENUM_CAT = tagHH_ENUM_CAT; {$EXTERNALSYM HH_ENUM_CAT} PHH_ENUM_CAT = ^tagHH_ENUM_CAT; {$EXTERNALSYM PHH_ENUM_CAT} THHEnumCat = tagHH_ENUM_CAT;
PHHSetInfoType = ^THHSetInfoType; tagHH_SET_INFOTYPE = packed record cbStruct: Integer; // the size of this structure pszCatName: LPCSTR; // the name of the category, if any, the InfoType is a member of. pszInfoTypeName: LPCSTR; // the name of the info type to add to the filter end; {$EXTERNALSYM tagHH_SET_INFOTYPE} HH_SET_INFOTYPE = tagHH_SET_INFOTYPE; {$EXTERNALSYM HH_SET_INFOTYPE} PHH_SET_INFOTYPE = ^tagHH_SET_INFOTYPE; {$EXTERNALSYM PHH_SET_INFOTYPE} THHSetInfoType = tagHH_SET_INFOTYPE;
type PHHFtsQuery = ^THHFtsQuery; tagHH_FTS_QUERY = packed record cbStruct: Integer; // Sizeof structure in bytes. fUniCodeStrings: BOOL; // TRUE if all strings are unicode. pszSearchQuery: LPCTSTR; // String containing the search query. iProximity: LongInt; // Word proximity. fStemmedSearch: BOOL; // TRUE for StemmedSearch only. fTitleOnly: BOOL; // TRUE for Title search only. fExecute: BOOL; // TRUE to initiate the search. pszWindow: LPCTSTR; // Window to display in end; {$EXTERNALSYM tagHH_FTS_QUERY} HH_FTS_QUERY = tagHH_FTS_QUERY; {$EXTERNALSYM HH_FTS_QUERY} THHFtsQuery = tagHH_FTS_QUERY;
PHHWinType = ^THHWinType; tagHH_WINTYPE = packed record cbStruct: Integer; // IN: size of this structure including all Information Types fUniCodeStrings: BOOL; // IN/OUT: TRUE if all strings are in UNICODE pszType: LPCTSTR; // IN/OUT: Name of a type of window fsValidMembers: DWORD; // IN: Bit flag of valid members (HHWIN_PARAM_) fsWinProperties: DWORD; // IN/OUT: Properties/attributes of the window (HHWIN_)
pszCaption: LPCTSTR; // IN/OUT: Window title dwStyles: DWORD; // IN/OUT: Window styles dwExStyles: DWORD; // IN/OUT: Extended Window styles rcWindowPos: TRect; // IN: Starting position, OUT: current position nShowState: Integer; // IN: show state (e.g., SW_SHOW)
hwndHelp: HWND; // OUT: window handle hwndCaller: HWND; // OUT: who called this window
paInfoTypes: PHHInfoType; // IN: Pointer to an array of Information Types
{ The following members are only valid if HHWIN_PROP_TRI_PANE is set }
hwndToolBar: HWND; // OUT: toolbar window in tri-pane window hwndNavigation: HWND; // OUT: navigation window in tri-pane window hwndHTML: HWND; // OUT: window displaying HTML in tri-pane window iNavWidth: Integer; // IN/OUT: width of navigation window rcHTML: TRect; // OUT: HTML window coordinates
pszToc: LPCTSTR; // IN: Location of the table of contents file pszIndex: LPCTSTR; // IN: Location of the index file pszFile: LPCTSTR; // IN: Default location of the html file pszHome: LPCTSTR; // IN/OUT: html file to display when Home button is clicked fsToolBarFlags: DWORD; // IN: flags controling the appearance of the toolbar fNotExpanded: BOOL; // IN: TRUE/FALSE to contract or expand, OUT: current state curNavType: Integer; // IN/OUT: UI to display in the navigational pane tabpos: Integer; // IN/OUT: HHWIN_NAVTAB_TOP, HHWIN_NAVTAB_LEFT, or HHWIN_NAVTAB_BOTTOM idNotify: Integer; // IN: ID to use for WM_NOTIFY messages tabOrder: array[0..HH_MAX_TABS] of Byte; // IN/OUT: tab order: Contents, Index, Search, History, Favorites, Reserved 1-5, Custom tabs cHistory: Integer; // IN/OUT: number of history items to keep (default is 30) pszJump1: LPCTSTR; // Text for HHWIN_BUTTON_JUMP1 pszJump2: LPCTSTR; // Text for HHWIN_BUTTON_JUMP2 pszUrlJump1: LPCTSTR; // URL for HHWIN_BUTTON_JUMP1 pszUrlJump2: LPCTSTR; // URL for HHWIN_BUTTON_JUMP2 rcMinSize: TRect; // Minimum size for window (ignored in version 1) cbInfoTypes: Integer; // size of paInfoTypes; {$IFDEF HTMLHELP12} pszCustomTabs: LPCTSTR; // multiple zero-terminated Strings {$ENDIF} end; {$EXTERNALSYM tagHH_WINTYPE} HH_WINTYPE = tagHH_WINTYPE; {$EXTERNALSYM HH_WINTYPE} PHH_WINTYPE = ^tagHH_WINTYPE; {$EXTERNALSYM PHH_WINTYPE} THHWinType = tagHH_WINTYPE;
{$IFDEF HTMLHELP_DYNAMIC_LINK} function HtmlHelpLoaded: Boolean; {$IFDEF HTMLHELP_DYNAMIC_LINK_EXPLICIT} function LoadHtmlHelp: Boolean; function UnLoadHtmlHelp: Boolean; {$ENDIF} {$ENDIF}
function GetFileName: String; function HelpFunc(Command : Word; Data : Longint; Var CallHelp : Boolean) : Boolean; function GetHHString(Topic: String): String; protected function DoHtmlHelp(uCommand: UINT; dwData: DWORD): HWND; public constructor Create(AOwner:TComponent);override; destructor Destroy; override;
function HelpContext(ContextId: DWord): Integer; function HelpTopic(Topic: String): Integer; function ShowIndex:integer; function ShowTableofContents:integer; function ShowSearch:integer; published property FileName: String read GetFileName write FFileName; property WinDef: String read FWindef write fWindef; end;
//取帮助文件名 function HelpFileName: String; //根据 ContextId 调用帮助 function ShowHelpContext(ContextId: DWord): Integer; //根据检索字符调用帮助 function ShowHelpTopic(Topic: String): Integer; //显示主帮助窗口 function ShowHelpWindow: Integer; //显示主帮助窗口的索引栏 function ShowHelpIndex: Integer; //显示主帮助窗口的搜索栏 function ShowHelpSearch: Integer; //设置主帮助文件名 procedure SetHelpFileName(FileName: String);
var Helper: THtmlHelp;
implementation
procedure CheckHelper; begin if not Assigned(Helper) then Helper := THtmlHelp.Create(Application); end;
procedure SetHelpFileName(FileName: String); begin CheckHelper; Helper.FileName := FileName; end;
function HelpFileName: String; begin CheckHelper; Result := Helper.FileName; end;
function ShowHelpTopic(Topic: String): Integer; begin CheckHelper; Result := Helper.HelpTopic(Topic); end;
function ShowHelpContext(ContextId: DWord): Integer; begin CheckHelper; Result := Helper.HelpContext(ContextID); end;
function ShowHelpWindow: Integer; begin CheckHelper; Result := Helper.ShowTableofContents; end;
function ShowHelpSearch: Integer; begin CheckHelper; Result := Helper.ShowSearch; end;
function ShowHelpIndex: Integer; begin CheckHelper; Result := Helper.ShowIndex; end;
function GetOCXPath(var Path: string): Boolean; const HHPathRegKey = 'CLSID\{adb880a6-d8ff-11cf-9377-00aa003b7a11}\InprocServer32'; begin with TRegistry.Create do try RootKey := HKEY_CLASSES_ROOT; if OpenKeyReadOnly(HHPathRegKey) then Path := ReadString(''); Result := (Path <> '') and FileExists(Path); finally Free; end; end;
function HtmlHelpLoaded: Boolean; begin Result := HtmlHelpLib <> 0; end;
function UnLoadHtmlHelp: Boolean; begin Result := True; if HtmlHelpLoaded then begin if Assigned(HtmlHelp) then HtmlHelp(0, nil, HH_CLOSE_ALL, 0); Result := FreeLibrary(HtmlHelpLib); HtmlHelpLib := 0; @HtmlHelpA := nil; @HtmlHelpW := nil; @HtmlHelp := nil; end; end;
function LoadHtmlHelp: Boolean; const ProcNameA = 'HtmlHelpA'; ProcNameW = 'HtmlHelpW'; ProcName = ProcNameA; var HHOCXPath: string; begin Result := HtmlHelpLoaded; if (not Result) and GetOCXPath(HHOCXPath) then begin HtmlHelpLib := LoadLibrary(PChar(HHOCXPath)); if HtmlHelpLoaded then begin @HtmlHelpA := GetProcAddress(HtmlHelpLib, ProcNameA); @HtmlHelpW := GetProcAddress(HtmlHelpLib, ProcNameW); @HtmlHelp := GetProcAddress(HtmlHelpLib, ProcName); Result := Assigned(HtmlHelpA) and Assigned(HtmlHelpW); if not Result then UnLoadHtmlHelp; end; end; end; {$ELSE} const hhctrl = 'hhctrl.ocx';
function HtmlHelpA; external hhctrl Name 'HtmlHelpA'; {$EXTERNALSYM HtmlHelpA} function HtmlHelpW; external hhctrl Name 'HtmlHelpW'; {$EXTERNALSYM HtmlHelpW} function HtmlHelp; external hhctrl Name 'HtmlHelpA'; {$EXTERNALSYM HtmlHelp} {$ENDIF}
FOldHelpEvent := Application.OnHelp; if not (csdesigning in ComponentState) then Application.OnHelp := HelpFunc; end;
destructor THTMLHelp.Destroy; begin Application.OnHelp := FOldHelpEvent; inherited destroy; end;
function THtmlHelp.getHHString(Topic: String): String; begin Result := FileName; if Length(Topic)>0 then Result := Result + '::' + Topic; if Length(WinDef)>0 then Result := Result + '>' + WinDef; end;
function THTMLHelp.HelpFunc(Command : Word; Data : Longint; Var CallHelp : Boolean) : Boolean; begin CallHelp := False; if (Command in [Help_Context, Help_ContextPopup]) then begin CallHelp := false; HelpContext( Data ); end else if Command=HELP_Finder then DoHtmlHelp(HH_DISPLAY_TOC, 0); Result := true; end;
function THTMLHelp.DoHtmlHelp(uCommand: UINT; dwData: DWORD): HWND; begin if (FileName='') or not FileExists(FileName) then Exit; Result := HtmlHelp(Application.Handle, PChar(GetHHString('')), uCommand, dwData); end;
function THTMLHelp.GetFileName: String; begin if not (csdesigning in componentstate) then begin if FFileName='' then FFileName := Application.Helpfile;
if ExtractFilePath(FFileName)='' then FFileName:= ExtractFilePath(Application.Exename) + FFileName;
if not FileExists(FFileName) then FFileName := ExtractFilePath(Application.Exename) + 'help.chm'; end; Result := FFileName; end;
function THTMLHelp.HelpContext(ContextId: DWord): Integer; begin Result := DoHtmlHelp(HH_HELP_CONTEXT, ContextID); end;
function THTMLHelp.HelpTopic(Topic: String): Integer; begin Result := DoHtmlHelp(HH_DISPLAY_TOPIC, 0); end;
function THTMLHelp.ShowIndex: Integer; begin Result := DoHtmlHelp(HH_DISPLAY_INDEX, 0); end;
function THTMLHelp.ShowTableofContents: Integer; begin Result := DoHtmlHelp(HH_DISPLAY_TOC, 0); end;
function THTMLHelp.ShowSearch: integer; var q:THHFTSQUERY; begin q.cbStruct:=sizeof(q); q.fUniCodeStrings:=false; q.pszSearchQuery:=nil; q.iProximity:=HH_FTS_DEFAULT_PROXIMITY; q.fStemmedSearch := FALSE ; q.fTitleOnly := FALSE ; q.fExecute := True ; q.pszWindow := nil ;
Result := DoHtmlHelp(HH_DISPLAY_SEARCH, DWord(@q)); end;
{$IFDEF HTMLHELP_DYNAMIC_LINK} initialization {$IFNDEF HTMLHELP_DYNAMIC_LINK_EXPLICIT} LoadHtmlHelp; {$ENDIF} finalization UnLoadHtmlHelp; if Assigned(Helper) then Helper.Free; {$ENDIF}