home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kompon / d6 / HHCOMP6.ZIP / HHComp.pas < prev    next >
Pascal/Delphi Source File  |  2001-10-05  |  3KB  |  107 lines

  1. unit HHComp;
  2. {This is freeware Delphi 6 unit which allow to use HTMLHelp instead of usual Windows Help
  3.  intercepting onkeydown event. Using this component you can still use HelpContext properties
  4.  of the components but THHComp sends help requests directly to the HTMLHelp API.
  5.  Component should be placed on every form which uses HTMLHelp system.
  6.  Version 2.0
  7.  Copyright (c) 2001 Ainars Skangals 
  8.  http://balder.prohosting.com/ainars/Delphi.shtml
  9.  This component is provided "as is" without warranty of any kind,
  10.  either expressed or implied.
  11. }
  12. interface
  13.  
  14. uses
  15.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
  16.  
  17. type
  18.   THHComp = class(TComponent)
  19.   private
  20.     { Private declarations }
  21.     FHelp,
  22.     FHelp1:String;
  23.     fOnOldKeyDown:TKeyEvent;
  24.   protected
  25.     { Protected declarations }
  26.     procedure Loaded; override;
  27.   public
  28.     { Public declarations }
  29.     Function ShowContents:Integer;
  30.     Function ShowIndex:Integer;
  31.     Procedure ShowHelp(Sender: TObject; var Key: Word; Shift: TShiftState);
  32. //    Function ShowHelp(Command: Word; Data: Longint; var CallHelp: Boolean): Boolean;
  33.     Destructor Destroy; override;
  34.   published
  35.     { Published declarations }
  36.     Property HelpFile:String read FHelp write FHelp;
  37.   end;
  38.  
  39. procedure Register;
  40.  
  41. implementation
  42. const
  43.   HH_DISPLAY_TOPIC  = $0000;
  44.   HH_DISPLAY_TOC    = $0001;
  45.   HH_DISPLAY_INDEX  = $0002;
  46.   HH_HELP_CONTEXT   = $000F;
  47.   HH_CLOSE_ALL      = $0012;
  48.  
  49. function HHelp(hwndCaller : HWND; pszFile: PChar; uCommand : Integer;
  50.             dwData : DWORD) : HWND; stdcall; external 'hhctrl.ocx' name 'HtmlHelpA';
  51.  
  52. function THHComp.ShowContents:Integer;
  53. begin
  54.    Result:=HHelp(Application.Handle,PChar(FHelp1),HH_DISPLAY_TOC,0);
  55. end;
  56.  
  57. function THHComp.ShowIndex:Integer;
  58. begin
  59.    Result:=HHelp(Application.Handle,PChar(FHelp),HH_DISPLAY_INDEX,0);
  60. end;
  61.  
  62. Procedure THHComp.ShowHelp(Sender: TObject; var Key: Word; Shift: TShiftState);
  63. var data:longint;
  64.     Control:TControl;
  65. begin
  66. data:=0; Control:=nil;
  67. if (Shift=[])and(Key=VK_F1) then begin
  68.  if (Owner as TForm).Activecontrol.HelpContext<>0 then data:=(Owner as TForm).Activecontrol.HelpContext;
  69.  if data=0 then
  70.   if (Owner as TForm).Activecontrol.Owner is TControl then begin
  71.     Control:=((Owner as TForm).Activecontrol.Owner as TControl);
  72.     if Control.HelpContext<>0 then data:=Control.HelpContext;
  73.     end;
  74.  if (data=0) and ((Owner as TForm).HelpContext<>0) then data:=(Owner as TForm).HelpContext; 
  75.  if FHelp<>'' then
  76.    HHelp(Application.Handle,PChar(FHelp1),HH_HELP_CONTEXT,Data);
  77.  //  CallHelp:=False;
  78.  Key:=0;  
  79.  end;
  80.  if assigned(fOnOldKeyDown) then fOnOldKeyDown(sender,key,shift)
  81. end;
  82.  
  83. procedure THHComp.Loaded;
  84. begin
  85. Inherited;
  86. // Here the help system is switched to HTMLHelp
  87. //HelpSystem:=
  88.  if assigned((Owner as TForm).onkeydown) then fOnOldKeyDown:=(Owner as TForm).onkeydown;
  89.  (Owner as TForm).OnKeyDown:=ShowHelp;
  90.  (Owner as TForm).KeyPreview:=true;
  91.  FHelp1:=ExtractFilePath(Application.exename)+FHelp;
  92. end;
  93.  
  94. destructor THHComp.Destroy;
  95. begin
  96.  // Automatically close help window if any
  97.  HHelp(0,PChar(FHelp1),HH_CLOSE_ALL,0);
  98.  inherited;
  99. end;
  100.  
  101. procedure Register;
  102. begin
  103.   RegisterComponents('Install', [THHComp]);
  104. end;
  105.  
  106. end.
  107.