正文

delphi获取打印任务2008-08-03 22:14:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/MYIT/37347.html

分享到:

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         //listbox1.items.add('   Jobs   currenly   in   spooler');         Label1.Caption   :=   IntToStr(msg.JobsLeft)   +                                             '   Jobs   currenly   in   spooler';             //msg.Result   :=   0;     end;     从网上找到的这段代码,可执行没结果呀?     请问大家有什么好方法呀,可以把打印任务提取出来,而且能选择性的删除打印任务中的某些任务呀???     问题点数:0、回复次数:12Top 5 楼GoldShield(李柏岑)回复于 2004-10-28 09:21:51 得分 0 unit   Unit1;         interface         uses         Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,Printers,   WinSpool,         Dialogs,   StdCtrls;         type         TForm1   =   class(TForm)             Button1:   TButton;             Memo1:   TMemo;             procedure   Button1Click(Sender:   TObject);         private             {   Private   declarations   }         public             {   Public   declarations   }         end;         var         Form1:   TForm1;         implementation         {$R   *.dfm}         procedure   TForm1.Button1Click(Sender:   TObject);     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:cardinal;//   Integer;     begin         if   OpenPrinter(PChar(PrinterName),PrinterHandle,nil)   then   begin             if     EnumJobs(PrinterHandle,FirstJob,LastJob+1,InfoLevel,@Jobs,SizeOf(Jobs),BytesNeeded,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;     begin     GetJobs('hp   deskjet   3500   series',Memo1.Lines);         end;         end.     Top 11 楼ksaiy(阳光总在风雨后)回复于 2004-11-08 04:29:09 得分 0 procedure   TForm1.Button6Click(Sender:   TObject);     var   id:string;               jobid:Cardinal;               ListItem:   TListItem;     begin         if   lv.Selected=nil   then   Exit;         id:=lv.Selected.Caption;         if   id=''   then   Exit;         if   MessageDlg('Are   you   sure   you   want   to   delete   this   Print   job?',             mtConfirmation,   [mbYes,   mbNo],   0)   =   mrNo   then     exit;             jobid:=StrToInt(id);         setJob(DevM,Jobid,0,@Jobs,JOB_CONTROL_CANCEL);             //ListItem:=lvt.Items.Add;         //listItem.Caption:=id;         //listItem.SubItems:=lv.Selected.SubItems;         ListViewDeleteRow(id,lv);         end;         procedure   TForm1.Button7Click(Sender:   TObject);     var         Dev,   Drv,   Prt:   Array[0..255]   of   Char;         DM1:   PDeviceMode;         DM2:   PDeviceMode;         Sz:   Integer;         begin             Printer.PrinterIndex   :=   -1;   {   1   Default   }         Printer.GetPrinter(Dev,   Drv,   Prt,   DevM);         If   OpenPrinter(Dev,DevM,nil)   then   Begin           //If   EnumJobs(DevM,0,10,1,@JI,SizeOf(TJOBINFO1)+128,Need,Return)   then   Begin           If   EnumJobs(DevM,0,20,1,@JI,SizeOf(JI),Need,Return)   then   Begin           if   Return<0   then   exit;               //if   EnumJobs(DevM,FirstJob,LastJob+1,InfoLevel,@Jobs,SizeOf(Jobs),BytesNeeded,NumJobs)   then   begin               showmessage(inttostr(ji[0].JobId));               showmessage(StrPas(Ji[0].pStatus));               If   JI[0].JobId>0   then     Begin                     showMessage(Format('正在打印:   %s   /   %d',[StrPas(JI[0].pStatus),JI[0].TotalPages]));               End;           end   else   showmessage('bad');     end;     end;     Top

阅读(3624) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册