home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / VCL / APHOLDER.PAS next >
Pascal/Delphi Source File  |  1997-02-15  |  5KB  |  144 lines

  1. {*********************************************************}
  2. {                                                         }
  3. {    Calmira Visual Component Library 1.0                 }
  4. {    by Li-Hsin Huang,                                    }
  5. {    released into the public domain January 1997         }
  6. {                                                         }
  7. {*********************************************************}
  8.  
  9. unit Apholder;
  10.  
  11. { TAppHolder component }
  12.  
  13. { TAppHolder is a simple container component that provides design-time
  14.   access to TApplication's properties and events.  When the component
  15.   is loaded, it assigns its data to TApplication.
  16.  
  17.   You can use it to automatically create event handlers for TApplication
  18.   and TScreen just like events for visual controls -- just double click
  19.   on the event.
  20.  
  21.   In addition, there is the OnWndProc event which is, in effect, a fast
  22.   way to subclass the application's main window without going down to the
  23.   API level.  If you create an OnWndProc event, this is triggered each
  24.   time the application's WndProc is called, and you can process messages
  25.   that never generate an OnMessage event because they are sent directly
  26.   to the window procedure.
  27.  
  28.   For this event, return False to allow TApplication to continue processing
  29.   the message, and True to stop TApplication handling it further.  It is
  30.   especially useful to trap WM_ENDSESSION here so that your program can
  31.   save its layout etc. before Windows shuts down.
  32. }
  33.  
  34. interface
  35.  
  36. uses
  37.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  38.   Forms, Dialogs;
  39.  
  40. type
  41.   TAppHolder = class(TComponent)
  42.   private
  43.     { Private declarations }
  44.     FHelpFile : string;
  45.     FHintColor : TColor;
  46.     FHintPause : Integer;
  47.     FTitle : string;
  48.     FOnActivate : TNotifyEvent;
  49.     FOnDeactivate : TNotifyEvent;
  50.     FOnException : TExceptionEvent;
  51.     FOnHelp : THelpEvent;
  52.     FOnHint : TNotifyEvent;
  53.     FOnIdle : TIdleEvent;
  54.     FOnMessage : TMessageEvent;
  55.     FOnMinimize : TNotifyEvent;
  56.     FOnRestore : TNotifyEvent;
  57.     FOnShowHint : TShowHintEvent;
  58.     FOnWndProc : TWindowHook;
  59.     FOnActiveControlChange : TNotifyEvent;
  60.     FOnActiveFormChange : TNotifyEvent;
  61.   protected
  62.     { Protected declarations }
  63.     procedure Loaded; override;
  64.   public
  65.     { Public declarations }
  66.     constructor Create(AOwner : TComponent); override;
  67.     destructor Destroy; override;
  68.   published
  69.     { Published declarations }
  70.     property HelpFile : string read FHelpfile write FHelpFile;
  71.     property HintColor : TColor read FHintColor write FHintColor;
  72.     property HintPause : Integer read FHintPause write FHintPause default 800;
  73.     property Title : string read FTitle write FTitle;
  74.     property OnActivate : TNotifyEvent read FOnActivate write FOnActivate;
  75.     property OnDeactivate : TNotifyEvent read FOnDeactivate write FOnDeactivate;
  76.     property OnException : TExceptionEvent read FOnException write FOnException;
  77.     property OnHelp : THelpEvent read FOnHelp write FOnHelp;
  78.     property OnHint : TNotifyEvent read FOnHint write FOnHint;
  79.     property OnIdle : TIdleEvent read FOnIdle write FOnIdle;
  80.     property OnMessage : TMessageEvent read FOnMessage write FOnMessage;
  81.     property OnMinimize : TNotifyEvent read FOnMinimize write FOnMinimize;
  82.     property OnRestore : TNotifyEvent read FOnRestore write FOnRestore;
  83.     property OnShowHint : TShowHintEvent read FOnShowHint write FOnShowHint;
  84.     property OnWndProc : TWindowHook read FOnWndProc write FOnWndProc;
  85.     property OnActiveControlChange : TNotifyEvent read
  86.       FOnActiveControlChange write FOnActiveControlChange;
  87.     property OnActiveFormChange : TNotifyEvent read
  88.       FOnActiveFormChange write FOnActiveFormChange;
  89.   end;
  90.  
  91. procedure Register;
  92.  
  93. implementation
  94.  
  95.  
  96. constructor TAppHolder.Create(AOwner : TComponent);
  97. begin
  98.   inherited Create(AOwner);
  99.   FHintColor := $0080FFFF;
  100.   FHintPause := 800;
  101. end;
  102.  
  103.  
  104. destructor TAppHolder.Destroy;
  105. begin
  106.   if Assigned(FOnWndProc) then Application.UnHookMainWindow(FOnWndProc);
  107.   inherited Destroy;
  108. end;
  109.  
  110.  
  111. procedure TAppHolder.Loaded;
  112. begin
  113.   with Application do begin
  114.     if FHelpFile > '' then HelpFile := ExtractFilePath(ExeName) + FHelpFile;
  115.     HintColor := FHintColor;
  116.     HintPause := FHintPause;
  117.     if FTitle > '' then Title := FTitle;
  118.     OnActivate := FOnActivate;
  119.     OnDeactivate := FOnDeactivate;
  120.     OnException := FOnException;
  121.     OnHelp := FOnHelp;
  122.     OnHint := FOnHint;
  123.     OnIdle := FOnIdle;
  124.     OnMessage := FOnMessage;
  125.     OnMinimize := FOnMinimize;
  126.     OnRestore := FOnRestore;
  127.     OnShowHint := FOnShowHint;
  128.     if Assigned(FOnWndProc) then HookMainWindow(FOnWndProc);
  129.   end;
  130.  
  131.   with Screen do begin
  132.     OnActiveControlChange := FOnActiveControlChange;
  133.     OnActiveFormChange := FOnActiveFormChange;
  134.   end;
  135. end;
  136.  
  137.  
  138. procedure Register;
  139. begin
  140.   RegisterComponents('Samples', [TAppHolder]);
  141. end;
  142.  
  143. end.
  144.