Advertisement
FlyFar

abApplication.pas

Dec 19th, 2023
1,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.48 KB | Cybersecurity | 0 0
  1. unit abApplication;
  2.  
  3. interface
  4.   uses Windows;
  5.  
  6. type
  7.   TProcedure = procedure;
  8.   TApplication = class(TObject)
  9.   private
  10.     FStartup: TProcedure;
  11.     FMain: TProcedure;
  12.     FShutdown: TProcedure;
  13.     FTerminated: boolean;
  14.     function ProcessMessage(var Msg: TMsg): Boolean;
  15.   protected
  16.   public
  17.     property Startup: TProcedure read FStartup write FStartup;
  18.     property Main: TProcedure read FMain write FMain;
  19.     property Shutdown: TProcedure read FShutdown write FShutdown;
  20.     property Terminated: boolean read FTerminated write FTerminated;
  21.     procedure StayResident;
  22.     procedure Terminate;
  23.     procedure ProcessMessages;
  24.   end;
  25.  
  26. implementation
  27.  
  28. function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
  29. begin
  30.   Result := False;
  31.   if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
  32.   begin
  33.     Result := True;
  34.     if Msg.Message <> $0012 then
  35.     begin
  36.       TranslateMessage(Msg);
  37.       DispatchMessage(Msg);
  38.     end
  39.     else
  40.     begin
  41.       FTerminated := True;
  42.     end;
  43.   end;
  44. end;
  45.  
  46. procedure TApplication.ProcessMessages;
  47. var
  48.   Msg: TMsg;
  49. begin
  50.   while ProcessMessage(Msg) do;
  51. end;
  52.  
  53. procedure TApplication.Terminate;
  54. begin
  55.   FTerminated := True;
  56. end;
  57.  
  58. procedure TApplication.StayResident;
  59. var
  60.   Msg: TMsg;
  61. begin
  62.   if Assigned(FStartup) then FStartup;
  63.   while not FTerminated do
  64.   begin
  65.     while ProcessMessage(Msg) do;
  66.     Sleep(100);
  67.     if Assigned(FMain) then FMain;
  68.   end;
  69.   if Assigned(FShutdown) then FShutdown;
  70. end;
  71.  
  72. end.
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement