⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.~pas

📁 File Mon Downloader. File Mon Downloader.
💻 ~PAS
字号:
unit mainfrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ProcessList, ExtCtrls, Grids;

type
  TForm1 = class(TForm)
    ProcessList1: TProcessList;
    Label1: TLabel;
    Timer1: TTimer;
    Panel1: TPanel;
    Label2: TLabel;
    lblCPURATE: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    StringGrid: TStringGrid;
    lblAvailableRAM: TLabel;
    lblRAMSize: TLabel;
    procedure Timer1Timer(Sender: TObject);
    procedure StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var Arow, datalength : integer;
begin
   self.ProcessList1.Check := true;
   datalength := self.ProcessList1.Items.Count;

   self.StringGrid.RowCount := datalength + 1;
   for Arow := 1 to StringGrid.RowCount - 1 do StringGrid.Rows[Arow].Clear;

   for Arow := 0 to datalength - 1 do begin
     StringGrid.Cells[0,Arow + 1] := self.ProcessList1.Items.Items[Arow].ExeName;
     StringGrid.Cells[1,Arow + 1] := inttostr(self.ProcessList1.Items.Items[Arow].Handle);
     StringGrid.Cells[2,Arow + 1] :=
     floattostr(ProcessList1.items.items[ARow].cpuratio);
     StringGrid.Cells[3,Arow + 1] :=
     formatdatetime('YYYYMMDDHHNNSS', ProcessList1.items.items[ARow].KernelTime);
     StringGrid.Cells[4,Arow + 1] :=
     formatdatetime('YYYYMMDDHHNNSS', ProcessList1.items.items[ARow].UserTime);

   end;

   self.lblCPURATE.Caption := formatfloat('##,#0.###0',self.ProcessList1.CPURatio);
   self.lblRAMSize.Caption := formatfloat('##,#0.#0Kb',self.ProcessList1.RAMQty /1024);
   self.lblAvailableRAM.Caption := formatfloat('##,#0.#0Kb',self.ProcessList1.AvailRAMQTY/1024);
end;

procedure TForm1.StringGridDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
const titles : array[0..4] of String[30]
      = ('Process Name', 'PID', 'CPU', 'Kernel Time', 'User Time');
var
      XPos, YPos : integer;
      tmpValue : double;
begin
   with Sender as TDrawGrid do begin
      if Arow = 0 then begin
         Canvas.Brush.Color := clbtnface;
         Canvas.FillRect(Rect);

         settextalign(Canvas.Handle,TA_Center);
         XPos := (Rect.left + Rect.Right) div 2;
         YPos := 2;
         Canvas.textRect(Rect, XPos,Ypos, titles[Acol]);

      end else begin

         Case Acol of
          0 : begin
                 Canvas.Brush.Color := clwindow;
                 Canvas.FillRect(Rect);

                 settextalign(Canvas.Handle,TA_Left);
                 XPos := Rect.left + 3;
                 YPos := Rect.top + 2;
                 Canvas.textRect(Rect, XPos,Ypos, self.StringGrid.Cells[Acol,Arow]);
              end;
          1 :
              begin
                 Canvas.Brush.Color := clWindow;
                 Canvas.FillRect(Rect);

                 settextalign(Canvas.Handle,TA_Center);
                 XPos := (Rect.left + Rect.Right) div 2;
                 YPos :=  Rect.top + 2;
                 Canvas.textRect(Rect, XPos,Ypos,
                 self.StringGrid.Cells[Acol,Arow]);
              end;
          2 :
              begin
                 Canvas.Brush.Color := clWindow;
                 Canvas.FillRect(Rect);

                 settextalign(Canvas.Handle,TA_Center);
                 XPos := (Rect.left + Rect.Right) div 2;
                 YPos :=  Rect.top + 2;
                 tmpvalue := strtofloatdef(self.StringGrid.Cells[Acol,Arow],0.0);
                 Canvas.textRect(Rect, XPos,Ypos,
                 formatfloat('##,#0.#0',tmpvalue) + '%');
              end;

          3,4 :
              begin
                 Canvas.Brush.Color := clWindow;
                 Canvas.FillRect(Rect);

                 settextalign(Canvas.Handle,TA_Center);
                 XPos := (Rect.left + Rect.Right) div 2;
                 YPos :=  Rect.top + 2;
                 Canvas.textRect(Rect, XPos,Ypos, 
                 copy(self.StringGrid.Cells[Acol,Arow],9,2) + ':' +
                 copy(self.StringGrid.Cells[Acol,Arow],11,2) + ':' +
                 copy(self.StringGrid.Cells[Acol,Arow],13,2) );
              end;

         end;

      end;

   end;
end;

end.

⌨️ 快捷键说明

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