监视打印机部分线程内容

2008-02-23 07:22:51来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

分  类:硬件
语  种:简体中文
编辑器:Delphi6
平  台:Win2k/XP/NT
作品源代码: -
软件或演示: -
代码大小: -
软件大小: -

unit UTrdGetJobs;

interface

uses
Classes,winspool,Windows,SysUtils;

type
TCallBack=Procedure(JobRecord:String) of Object;

TGetJobs = class(TThread)
private

protected
FPrinterName:String;
FCallBack:TCallBack;
Function GetJob():String;Virtual;Abstract;
procedure Execute; override;
Public
constructor Create(PrinterName:String;ACallBack:TCallBack);
end;

TGetJobs9X=Class(TGetJobs)
Protected
Function GetJob():String;Override;
end;

TGetJobsNT=Class(TGetJobs)
Protected
Function GetJob():String;Override;
end;

implementation

{ Important: Methods and properties of objects in VCL or CLX can only be used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like,
procedure TrdGetJobs.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }

{ TrdGetJobs }

constructor TGetJobs.Create(PrinterName: String; ACallBack: TCallBack);
begin
FPrinterName:=PrinterName;
FCallBack:=ACallBack;

FreeOnTerminate := True;
inherited Create(False);
end;

procedure TGetJobs.Execute;
begin
while not Terminated do
begin
FCallBack(GetJob);
end;
end;

{ TGetJobsNT }

function TGetJobsNT.GetJob: String;
Const
InfoLevel = 1;
FirstJob = 0;
LastJob = 19;
Var
Jobs: Array[FirstJob..LastJob] Of TJobInfo1;
BytesNeeded,NumJobs: Dword;
hPrinter:THandle;
JobsRecord:String;
begin
JobsRecord:=';
if OpenPrinter(Pchar(FPrinterName),hPrinter,nil) then
begin
WaitForPrinterChange(hPrinter,PRINTER_CHANGE_ADD_JOB);
If EnumJobs(hPrinter,FirstJob,LastJob 1,InfoLevel,@Jobs,SizeOf(Jobs),BytesNeeded,NumJobs) Then
begin
if NumJobs<>0 then
begin
With Jobs[NumJobs-1] Do
begin
JobsRecord:=JobsRecord StrPas(pDocument) #9;
JobsRecord:=JobsRecord StrPas(pPrinterName) #9;
JobsRecord:=JobsRecord StrPas(pMachineName) #9;
JobsRecord:=JobsRecord StrPas(pUserName) #9;
JobsRecord:=JobsRecord IntToStr(TotalPages) #9;
JobsRecord:=JobsRecord DateTimeToStr(SystemTimeToDateTime(Submitted) 8/24) #9;
end;
end;
end;
ClosePrinter(hPrinter);
end;
Result:=JobsRecord;
end;

{ TGetJobs9X }

function TGetJobs9X.GetJob: String;
begin
//
end;

end.

上一篇: 预览式文件选择对话框示例
下一篇: FastReprot3 基础使用方法示例

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:初步实现在屏幕上‘下雪’的效果

下一篇:自动注册SOHU用户小程序