Menu

[r4761]: / branches / parsnip / Src / UHTMLHelpMgr.pas  Maximize  Restore  History

Download this file

125 lines (105 with data), 4.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2007-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Provides a class that implements the IHelpMgr interface using the HTML Help
* system and registers an instantiation of the class as the program's
* help manager.
}
unit UHTMLHelpMgr;
interface
implementation
uses
// Delphi
Windows,
// Project
UAppInfo, UEncodings, UHelpMgr;
type
/// <summary>Structure used to specify one or more ALink names or KLink
/// keywords to be searched for.</summary>
/// <remarks>The LPCTSTR fields behave strangely when using the Unicode API.
/// In this case LPCTSTR is defined as PWideChar, but casting a Unicode
/// string to a PChar (=PWideChar) causes HTML Help to see only the first
/// character of the keyword, implying HTML Help is treating the string an
/// ANSI string. To get this to work a Unicode Delphi string must first be
/// cast to an ANSI string and then to a pointer before assiging to the
/// LPCTSTR valued field.</remarks>
THHAKLink = packed record
/// <summary>Size of record in bytes.</summary>
cbStruct: Integer;
/// <summary>Reserved. Must be False.</summary>
fReserved: BOOL;
/// <summary>Semi-colon separated keywords.</summary>
pszKeywords: LPCTSTR;
/// <summary>URL to jump to if none of the keywords are found (may be nil).
/// </summary>
pszUrl: LPCTSTR;
/// <summary>Text to be displayed in a message box on failure (may be nil).
/// </summary>
pszMsgText: LPCTSTR;
/// <summary>Title of any failure message box.</summary>
pszMsgTitle: LPCTSTR;
/// <summary>Name of window where pszUrl is to be displayed.</summary>
pszWindow: LPCTSTR;
/// <summary>Flag determining if help index is displayed if keyword lookup
/// fails.</summary>
fIndexOnFail: BOOL;
end;
/// <summary>Class that implements the help manager interface for the HTML
/// help system.</summary>
THTMLHelpMgr = class(TInterfacedObject, IHelpMgr)
strict private
/// <summary>Calls HtmlHelp API function with given command, help page and
/// parameters.</summary>
/// <param name="Command">UINT [in] Command to send to HTML Help.</param>
/// <param name="HelpPage">string [in] Name of required HTML topic "file"
/// within help file. May be empty string if no specific page is required.
/// </param>
/// <param name="Data">DWORD [in] Data to pass to HTML Help. Meaning
/// depends on Command.</param>
procedure DoAppHelp(const Command: UINT; const HelpPage: string;
const Data: DWORD);
public
/// <summary>Displays any help topics that match the given A-Link keyword.
/// </summary>
procedure ShowHelp(const AKeyword: string);
/// <summary>Displays HTML help contents tab and default help page.
/// </summary>
procedure ShowContents;
end;
{ THTMLHelpMgr }
procedure THTMLHelpMgr.DoAppHelp(const Command: UINT; const HelpPage: string;
const Data: DWORD);
var
HelpSpec: string; // Help file name followed by any required topic page
begin
HelpSpec := TAppInfo.HelpFileName;
if HelpPage <> '' then
HelpSpec := HelpSpec + '::/' + HelpPage;
HtmlHelp(GetDesktopWindow(), HelpSpec, Command, Data);
end;
procedure THTMLHelpMgr.ShowContents;
begin
DoAppHelp(HH_DISPLAY_TOC, '', 0);
end;
procedure THTMLHelpMgr.ShowHelp(const AKeyword: string);
var
ALink: THHAKLink; // structure containing details of A-Link
begin
ZeroMemory(@ALink, SizeOf(THHAKLink));
ALink.cbStruct := SizeOf(THHAKLink);
// See remarks for THHAKLink for explanation of the following string casts.
ALink.pszKeywords := Pointer(StringToASCIIString(AKeyword));
ALink.fIndexOnFail := True;
// We pass "pointer" to ALink as command's data
DoAppHelp(HH_ALINK_LOOKUP, '', DWORD(@ALink));
end;
initialization
RegisterHelpMgr(THTMLHelpMgr.Create);
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.