logbook.dpr

来自「是和Delphi 编程精选集锦书本配套的源码」· DPR 代码 · 共 99 行

DPR
99
字号
{*******************************************************}
{                                                       }
{       A Windows program for log StartUp and           }
{       ShutDown time of computer                       }
{                                                       }
{       Copyright(c) 1999..2000,  Su Chengxiang         }
{                                                       }
{*******************************************************}

Program Logbook;

uses
  Windows, SysUtils,
  TinyApp in 'TinyApp.pas',
  LogFile in 'LogFile.pas',
  SuObject in 'SuObject.pas';
{$R Logbook0.RES}

const
  LogName: shortstring = 'Logbook.txt';

type
  PLogbookApp = ^TLogbookApp;
  TLogbookApp = object(TTinyApp)
    FDTLogFile: PTimeLogFile;
    constructor Create(AName: PChar);
    destructor Destroy; virtual;
    function DoOnStart: Bool; virtual;
    function DoOnExit: Bool; virtual;
    procedure InitMainWindow; virtual;
  end;

{ TLogbookApp }

constructor TLogbookApp.Create(AName: PChar);
var
  AIcon: HICON;
  Str1: String;
begin
  inherited Create(AName);
  Str1:= Concat(PathStr, LogName);
  FDTLogFile:= New(PTimeLogFile, Create(Str1));
  if (FDTLogFile = nil) then
   begin
    ProcessError;
    FTerminate:= True;
   end;
  if FTrayIcon <> nil then
   begin
    DateTimeToString(Str1, '"开机 "hh:nn', StartUpTime);
    AIcon:= LoadIcon(FHInstance, 'MAINICON');
    FTrayIcon^.Add(IDI_MyFirst+1, AIcon, Str1);
   end;
end;

destructor TLogbookApp.Destroy;
begin
  if (FDTLogFile <> nil) then FDTLogFile^.Free;
  inherited Destroy;
end;

function TLogbookApp.DoOnStart: Bool;
begin
  FDTLogFile^.WriteStartUpTime;
  Result:= True;
end;

function TLogbookApp.DoOnExit: Bool;
begin
  FDTLogFile^.WriteShutDownTime;
  Result:= True;
end;

procedure TLogbookApp.InitMainWindow;
begin
  FMainWindow:= new(PMainWindow, Create('Logbook v1.0'));
end;


var
  MyApp: PLogbookApp;

procedure WinMain(hInstCurrent,             // handle to current instance
                  hInstPrev: HINST;         // handle to previous instance
                  lpszCmdLine: LPSTR;       // pointer to command line
                  nCmdShow: integer);       // show state of window
var  R: Integer;
begin
  MyApp:= New(PLogbookApp, Create('Logbook'));
  MyApp^.Run;
  R:= MyApp^.FReturnValue;
  MyApp^.Free;
  Halt(R);
end;

begin
  WinMain(hInstance, hPrevInst, CmdLine, CmdShow);
end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?