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

📄 得到打印机的任务数.txt

📁 大量Delphi开发资料
💻 TXT
字号:
 Procedure TFormX.WMSpoolerstatus( Var msg: TWMSpoolerStatus );

 Begin

   label1.caption:= Format('Spooler status code: %d', 

                           [ msg.JobStatus ]);

   label2.caption:= Format('Jobs left: %d', [msg.JobsLeft]);   

 End;


******************************************************************************************
type

  TForm1 = class(TForm)

    Label1: TLabel;

  private

    { Private declarations }

    procedure WM_SpoolerStatus(var Msg : TWMSPOOLERSTATUS); message WM_SPOOLERSTATUS;

  public

    { Public declarations }

  end;


var

  Form1: TForm1;


implementation


{$R *.DFM}


procedure TForm1.WM_SpoolerStatus(var Msg : TWMSPOOLERSTATUS);

begin

  Lable1.Caption := IntToStr(msg.JobsLeft)+' Jobs currenly in spooler';

  msg.Result := 0;

end;




************************************************************************************

uses Printers, WinSpool;


function PrinterStatusText(Status: Integer): String;

begin

  case Status of

    0:                            Result := 'Waiting';

    JOB_STATUS_PAUSED:            Result := 'Paused';

    JOB_STATUS_ERROR:             Result := 'Error';

    JOB_STATUS_DELETING:          Result := 'Deleting';

    JOB_STATUS_SPOOLING:          Result := 'Spooling';

    JOB_STATUS_PRINTING:          Result := 'Printing';

    JOB_STATUS_OFFLINE:           Result := 'Offline';

    JOB_STATUS_PAPEROUT:          Result := 'Paper Out';

    JOB_STATUS_PRINTED:           Result := 'Printed';

    JOB_STATUS_DELETED:           Result := 'Deleted';

    JOB_STATUS_BLOCKED_DEVQ:      Result := 'Blocked';

    JOB_STATUS_USER_INTERVENTION: Result := 'User Intervention';

    JOB_STATUS_RESTART:           Result := 'Restart';

  else Result := 'Status ' + IntToStr(Status);

  end;

end;


procedure GetJobs(PrinterName: String; JobList: TStrings);

const

  InfoLevel = 1;

  FirstJob = 0;

  LastJob = 19;

var

  Jobs: array [FirstJob..LastJob] of TJobInfo1;

  PrinterHandle, BytesNeeded, I, NumJobs: Integer;

begin

  if OpenPrinter(PChar(PrinterName),PrinterHandle,nil) then begin

    if

EnumJobs(PrinterHandle,FirstJob,LastJob+1,InfoLevel,@Jobs,SizeOf(Jobs),BytesNeed

ed,NumJobs) then begin

      JobList.Clear;

      for I := 0 to NumJobs-1 do

      with Jobs[I] do

        JobList.Add(Format('%s

(%s)',[StrPas(pDocument),PrinterStatusText(Status)]));

    end;

    ClosePrinter(PrinterHandle);

  end;

end;


procedure TForm1.Button1Click(Sender: TObject);

begin

  GetJobs('HP Laserjet 4P',Memo1.Lines);

end;

⌨️ 快捷键说明

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