Home

News
News Archive

Articles
HTML Help

Forums / Groups

Mozilla-Delphi Project

Pascal Newsletter

Software

Links

Search

Vote For Us:
Irongut's Delphi Pages
Pascal Newsletter

Contact Details

Legal Stuff

Download
Using HTML Help in your Applications
By Dave Murray <irongut at vodafone dot net>

Do you long to move from WinHelp to HTML Help in your programs? The unit below converts WinHelp calls to HTML Help enabling you to upgrade with the minimum of effort.

This article first appeared as #2994 on Delphi3000.com and was later published in Issue #36 of the Pascal Newsletter.

Save the unit conHTMLHelp.pas to a directory on your Library Path (Tools | Environment Options | Library | Library Path) and add it to your project's uses clause. WinHelp requests will now be translated to HTML Help calls so you can use help files just as you previously did only now you are using HTML help files.

Specify your *.chm file in the Project Options | Application | Help file setting. Context sensitive help will work as it previously did. You can also directly invoke methods such as TApplication.HelpCommand to show your help file.

eg.
Application.HelpCommand(HELP_KEY, DWORD(keyData));
Application.HelpCommand(HELP_CONTEXT, 1003);

Notes

Delphi 6+

Since v6, Delphi does not pass all help calls to TApplication.OnHelp as it did in v2 - v5. You can still hook OnHelp but if you look at Forms.pas you will see that only TApplication.InvokeHelp makes the required call and then only if the current form's BorderIcons property contains biHelp. TApplication.HelpCommand still works because it calls InvokeHelp but all other help calls bypass InvokeHelp and call the Help Manager directly.

eg.
Application.HelpContext()
Application.HelpJump()

There is a fix available for this problem from The Helpware Group. Just include their D6OnHelpFix.pas unit in your project and all help events are diverted to TApplication.OnHelp like previous versions of Delphi.

The Code

unit conHTMLHelp;
{Unit to translate WinHelp requests into HTML Help and call the API.}
{Functions from "Abstracting Runtime Queries from Code" article on Irongut's Delphi Pages
 Written by Dave Murray, October 2001. Irongut's Delphi Pages : http://www.paranoia.clara.net
 (C) 2001 - 2003 Conspiracy Software <conspiracysoftware@hotmail.com>}

interface

uses
    Windows, Messages, SysUtils, Forms;

const
    {commands to pass to HtmlHelp(), see HTML Help API Reference}
    HH_DISPLAY_TOPIC        = $0000; {open help topic}
    HH_HELP_FINDER          = $0000; {compatibility, use HH_DISPLAY_TOPIC}
    HH_DISPLAY_TOC          = $0001; {select Contents tab in nav pane}
    HH_DISPLAY_INDEX        = $0002; {select Index + search for keyword}
    HH_DISPLAY_SEARCH       = $0003; {select Search tab in nav pane}
    HH_SET_WIN_TYPE         = $0004;
    HH_GET_WIN_TYPE         = $0005;
    HH_GET_WIN_HANDLE       = $0006;
    HH_ENUM_INFO_TYPE       = $0007;
    HH_SET_INFO_TYPE        = $0008;
    HH_SYNC                 = $0009;
    HH_RESERVED1            = $000A; {not currently implemented}
    HH_RESERVED2            = $000B; {not currently implemented}
    HH_RESERVED3            = $000C; {not currently implemented}
    HH_KEYWORD_LOOKUP       = $000D;
    HH_DISPLAY_TEXT_POPUP   = $000E; {display string resource/text popup}
    HH_HELP_CONTEXT         = $000F; {display topic for context number}
    HH_TP_HELP_CONTEXTMENU  = $0010; {text popup, like HELP_CONTEXTMENU}
    HH_TP_HELP_WM_HELP      = $0011; {text popup, like HELP_WM_HELP}
    HH_CLOSE_ALL            = $0012; {close all windows opened by caller}
    HH_ALINK_LOOKUP         = $0013; {ALink version of HH_KEYWORD_LOOKUP}
    HH_GET_LAST_ERROR       = $0014; {not currently implemented}
    HH_ENUM_CATEGORY        = $0015;
    HH_ENUM_CATEGORY_IT     = $0016;
    HH_RESET_IT_FILTER      = $0017;
    HH_SET_INCLUSIVE_FILTER = $0018;
    HH_SET_EXCLUSIVE_FILTER = $0019;
    HH_INITIALIZE           = $001C;
    HH_UNINITIALIZE         = $001D;
    HH_PRETRANSLATEMESSAGE  = $00FD;
    HH_SET_GLOBAL_PROPERTY  = $00FC;

function HtmlHelp(hwndCaller: THandle; pszFile: PChar;
    uCommand: cardinal; dwData: longint): THandle; stdcall;

implementation

function HtmlHelp(hwndCaller: THandle; pszFile: PChar;
    uCommand: cardinal; dwData: longint): THandle; stdcall;
    external 'hhctrl.ocx' name 'HtmlHelpA'; {external API call}

type
    TconHTMLHelp = class(TObject) {encapsulates function}
        function ApplicationHelp(Command: Word; Data: Longint;
            var CallHelp: Boolean): Boolean;
    end; {TconHTMLHelp..}

function TconHTMLHelp.ApplicationHelp(Command: Word; Data: Longint;
    var CallHelp: Boolean): Boolean;
{translates WinHelp commands to HTMLHelp commands + calls API}
var
    HCommand : word;
begin
    {make sure VCL doesn't activate WinHelp + function succeeds}
    CallHelp := false;
    result := true;
    {translate WinHelp > HTMLHelp}
    case Command of
        HELP_CONTENTS : begin
            HCommand :=  HH_DISPLAY_TOC;
            Data := 0;
            end; {HELP_CONTENTS..}
        HELP_CONTEXT : HCommand := HH_HELP_CONTEXT;
        HELP_CONTEXTPOPUP : HCommand := HH_HELP_CONTEXT;
        HELP_FINDER : HCommand := HH_DISPLAY_TOPIC;
        HELP_KEY : HCommand := HH_DISPLAY_INDEX;
        HELP_QUIT : begin
        HCommand :=  HH_CLOSE_ALL;
        Data := 0;
        end; {HELP_QUIT..}
    else begin {default}
        HCommand := HH_DISPLAY_TOPIC;
        Data := 0;
        end; {default..}
    end; {case Command..}
    {call HTML Help API}
    HtmlHelp(Application.MainForm.Handle, PChar(Application.HelpFile),
        HCommand, Data);
end; {function TconHTMLHelp.ApplicationHelp}

var
   hhHelper: TconHTMLHelp;

initialization
    {create object + assign event handler}
    hhHelper := TconHTMLHelp.Create;
    Application.OnHelp := hhHelper.ApplicationHelp;
finalization
    {free event handler + object}
    Application.OnHelp := nil;
    hhHelper.Free;
end.

Zip Download the code.

Refer this page to a friend!

Copyright © 2003 - 2010 Conspiracy Software. All Rights Reserved.