捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  沪ICP备05001939号 DELPHI盒子 | 盒子论坛 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 论坛检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
盒子资源分类
全部展开 - 全部合拢
监视打印机部分线程内容
关键字:UTrdGetJobs Printer 打印机 线程
来 自:原创
平 台:Win2k/XP/NT 下载所需:0 火柴
深浅度:中级 完成时间:2005/2/23
发布者:supermay 发布时间:2005/2/23
编辑器:DELPHI6 语  种:简体中文
分 类:硬件 下载浏览:0/13047
加入到我的收藏
下载错误报错
登陆以后才能下载
 用户名:
 密 码:
自动登陆(30天有效)
无图片
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.
Google
 
本站原创作品,未经作者许可,严禁任何方式转载;转载作品,如果侵犯了您的权益,请联系我们
龙脉加密锁 15元起 Grid++Report 报表 申请支付@网
 相关文章
没有相关文章
相关评论
共有评论3条 当前显示最后3条评论
dacsd 2005/2/24 9:31:21
如何在程序中调用?在delphi7中能否使用。
谢谢
dacsd 2005/2/24 9:32:08
能不能在WIN9X中使用?
supermay 2005/5/9 10:27:10
D6开发,在D7应没有问题,
没有写WIN9X部分的线程,在WIN9X下,监视SPOOL的消息
我要发表评论 查看全部评论
 
  DELPHI盒子版权所有 1999-2023 V4.01 粤ICP备10103342号-1 更新RSS列表