delphi 控制打印机任务(50分)

  • 主题发起人 主题发起人 【清风】
  • 开始时间 开始时间

【清风】

Unregistered / Unconfirmed
GUEST, unregistred user!
谁用delphi做过控制打印机任务的程序,能实现如下几个功能<br>1、截获打印任务,再通过程序控制是否可以打印再关到打印机<br>2、获取本地打印机列表,以及每个打印机的详细信息<br>请高手指点一下。<br>主要是第一个, 如果源码可用,再加200分或400分
 
怎么没有这方面的高手吗? 算帮忙了,成功后大大的加分。
 
我到是 做过 打印内容拦截<br>和 虚拟打印机<br><br>、获取本地打印机列表,以及每个打印机的详细信息<br>&nbsp;这个很简单啊
 
//仅供 &nbsp;ccdos 专用<br>//2004-11-28<br>// hfghfghfg <br><br>unit PrinterEvent;<br><br>interface<br>uses SysUtils, Messages, Windows, Classes, WinSpool, dateUtils, ExtCtrls;<br>const<br>&nbsp; PrinterInfoLevel = 2;<br>&nbsp; JobInfoLevel = 2;<br>&nbsp; RefreshInterval: Integer = 10;<br>&nbsp; WM_THREADERROR = WM_USER + 1;<br>&nbsp; WM_PRINTED = WM_USER + 2;<br>&nbsp; WM_JobEvent = WM_USER + 3;<br><br><br>type<br><br>&nbsp; PJobRecord = ^TJobRecord;<br>&nbsp; TJobRecord = record<br>&nbsp; &nbsp; ComputerName: string;<br>&nbsp; &nbsp; UserName: string;<br>&nbsp; &nbsp; PrinterName: string;<br>&nbsp; &nbsp; DocName: string;<br>&nbsp; &nbsp; SUBMITTED_datetime: TDateTime;<br>&nbsp; &nbsp; id: integer;<br>&nbsp; &nbsp; PageCount: Integer<br>&nbsp; end;<br>&nbsp; TJobEvent = procedure(Sender: TObject; JobRecord: TJobRecord) of object;<br><br><br><br>&nbsp; TPrinterNTThread = class(TThread)<br>&nbsp; private<br>&nbsp; &nbsp; FPrnHandle: THandle;<br>&nbsp; &nbsp; FPrnName: string;<br>&nbsp; &nbsp; FNotify: THandle;<br>&nbsp; &nbsp; FOptions: TPrinterNotifyOptions;<br>&nbsp; &nbsp; FOptionsType: TPrinterNotifyOptionsType;<br><br>&nbsp; &nbsp; FJobEvent: TJobEvent;<br><br>&nbsp; protected<br>&nbsp; &nbsp; procedure SetPrnName(V: string);<br>&nbsp; &nbsp; procedure DoJobEvent(J: TJobRecord);<br>&nbsp; public<br>&nbsp; &nbsp; FNowJobRecord: TJobRecord;<br>&nbsp; &nbsp; constructor Create(V: string); virtual;<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; &nbsp; procedure ForDoJobEvent;<br>&nbsp; &nbsp; procedure Execute; override;<br>&nbsp; &nbsp; property PrnName: string read FPrnName;<br>&nbsp; &nbsp; property onThreadJobEvent: TJobEvent read FJobEvent write FJobEvent;<br>&nbsp; end;<br><br><br><br><br><br><br>&nbsp; TPrinterEvent = class(TComponent)<br>&nbsp; private<br>&nbsp; &nbsp; FOnJobEvent: TJobEvent;<br>&nbsp; &nbsp; FTimer: TTimer;<br>&nbsp; &nbsp; FWaiteEventThread_List: array of TPrinterNTThread;<br>&nbsp; &nbsp; procedure ThreadJobEvent(Sender: TObject; JobRecord: TJobRecord);<br>&nbsp; protected<br>&nbsp; &nbsp; { Protected declarations }<br>&nbsp; public<br>&nbsp; &nbsp; constructor Create(AOwner: TComponent); override;<br>&nbsp; &nbsp; destructor Destroy; override;<br>&nbsp; &nbsp; procedure UpdatePrinters;<br>&nbsp; &nbsp; procedure onThreadTerminate(sender: TObject);<br>&nbsp; &nbsp; procedure OnTimer(sender: TObject);<br>&nbsp; published<br>&nbsp; &nbsp; { Published declarations }<br><br>&nbsp; &nbsp; property OnJobEvent: TJobEvent read FOnJobEvent write FOnJobEvent;<br>&nbsp; end;<br><br><br>implementation<br><br>procedure Register;<br>begin<br>&nbsp; RegisterComponents('Samples', [TPrinterEvent]);<br>end;<br>const<br>&nbsp; AFields: array[0..6] of Word<br>&nbsp; = (JOB_NOTIFY_FIELD_SUBMITTED, JOB_NOTIFY_FIELD_MACHINE_NAME, JOB_NOTIFY_FIELD_START_TIME, JOB_NOTIFY_FIELD_DOCUMENT, JOB_NOTIFY_FIELD_USER_NAME, JOB_NOTIFY_FIELD_TOTAL_PAGES, JOB_NOTIFY_FIELD_PAGES_PRINTED);<br><br><br><br>{ TPrinterNTThread }<br><br>constructor TPrinterNTThread.Create(V: string);<br>begin<br>&nbsp; SetPrnName(V);<br>&nbsp; inherited Create(True);<br>&nbsp; FreeOnTerminate := true;<br>end;<br><br>destructor TPrinterNTThread.Destroy;<br>begin<br>&nbsp; inherited;<br>end;<br><br>procedure TPrinterNTThread.DoJobEvent(J: TJobRecord);<br>begin<br>&nbsp; if assigned(FJobEvent) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; FNowJobRecord := j;<br>&nbsp; &nbsp; &nbsp; Synchronize(ForDoJobEvent);<br>&nbsp; &nbsp; end;<br>end;<br><br>procedure TPrinterNTThread.ForDoJobEvent;<br>begin<br>&nbsp; FJobEvent(self, FNowJobRecord);<br>end;<br><br>procedure TPrinterNTThread.Execute;<br>type<br>&nbsp; PInfoDatas = ^TInfoDatas;<br>&nbsp; TInfoDatas = array[0..31] of TPrinterNotifyInfoData;<br>var<br>&nbsp; i: integer;<br>&nbsp; AChange: Cardinal;<br><br>&nbsp; AInfo: Pointer;<br>&nbsp; P: PInfoDatas;<br>&nbsp; pc: pchar;<br>&nbsp; strTemp: string;<br>&nbsp; jobRec: TJobRecord;<br>&nbsp; sys_time: _SystemTime;<br>&nbsp; ZI: TTimeZoneInformation;<br>begin<br><br>&nbsp; AInfo := nil;<br>&nbsp; while (FPrnHandle &gt; 0) and (FNotify &gt; 0) and (not Terminated) do<br>&nbsp; &nbsp; begin<br><br>&nbsp; &nbsp; &nbsp; if WaitForSingleObject(FNotify, INFINITE) = WAIT_OBJECT_0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FreePrinterNotifyInfo(AInfo);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if not FindNextPrinterChangeNotification(FNotify, AChange, @FOptions, AInfo) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendError;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Continue;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; with PPrinterNotifyInfo(AInfo)^ do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; P := @aData;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i := 0 to count - 1 do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if p.wType = PRINTER_NOTIFY_TYPE then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case p.Field of<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_SERVER_NAME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_PRINTER_NAME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_SHARE_NAME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_PORT_NAME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_DRIVER_NAME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_COMMENT: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_LOCATION: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_DEVMODE: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_SEPFILE: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_PRINT_PROCESSOR: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_PARAMETERS: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_DATATYPE: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_SECURITY_DESCRIPTOR: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_ATTRIBUTES: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_PRIORITY: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_DEFAULT_PRIORITY: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_START_TIME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_UNTIL_TIME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_STATUS: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_STATUS_STRING: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_CJOBS: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_AVERAGE_PPM: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_TOTAL_PAGES: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_PAGES_PRINTED: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_TOTAL_BYTES: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINTER_NOTIFY_FIELD_BYTES_PRINTED: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if p.wType = JOB_NOTIFY_TYPE then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if i = 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.id := p.Id;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.SUBMITTED_datetime := now;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.PrinterName := PrnName;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.PageCount := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.id := p.Id;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (jobRec.id &lt;&gt; p.Id) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DoJobEvent(jobRec);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.id := p.Id;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.SUBMITTED_datetime := now;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.PrinterName := PrnName;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.PageCount := 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.id := p.Id;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case p.Field of<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_PRINTER_NAME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_MACHINE_NAME:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetLength(strTemp, p.NotifyData.Data.cbBuf);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Move(pchar(p.NotifyData.Data.pBuf)[0], strTemp[1], length(strTemp));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.ComputerName := pchar(strTemp);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strTemp := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_PORT_NAME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_USER_NAME:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetLength(strTemp, p.NotifyData.Data.cbBuf);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Move(pchar(p.NotifyData.Data.pBuf)[0], strTemp[1], length(strTemp));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.UserName := pchar(strTemp);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strTemp := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_NOTIFY_NAME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_DATATYPE: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_PRINT_PROCESSOR: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_PARAMETERS: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_DRIVER_NAME: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_DEVMODE: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_STATUS: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_STATUS_STRING: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_SECURITY_DESCRIPTOR: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_DOCUMENT:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SetLength(strTemp, p.NotifyData.Data.cbBuf);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Move(pchar(p.NotifyData.Data.pBuf)[0], strTemp[1], length(strTemp));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.DocName := StrPas(pchar(strTemp));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strTemp := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_PRIORITY: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_POSITION: ;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; JOB_NOTIFY_FIELD_SUBMITTED:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Move(p.NotifyData.Data.pBuf^, sys_time, Sizeof(sys_time));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jobRec.SUBMITTED_datetime := SystemTimeToDateTime(sys_time);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetTimeZoneInformation(zi);
 
hfghfghfg 兄弟,代码没粘完呀,是否可以把代码给发个邮件, bj_haiqing@163.com,<br>谢谢,完了给你积分
 
我也学习一下 delhpi@126.com 谢谢。
 
function GetPrintJobCount(var ErrMsg:String): Integer; &nbsp;//获取当前打印任务数目<br>var<br>&nbsp; Needed, Returned: DWORD;<br>&nbsp; pNeeded: PDword;<br>&nbsp; P2: PJobInfo1;<br>&nbsp; PPI: pPRINTERINFO2;<br>&nbsp; Printer: TPrinter;<br>&nbsp; Device, Driver, Port: array[0..255] of Char;<br>&nbsp; DevMode: Cardinal;<br>&nbsp; hPrinter: THandle;<br>begin<br>&nbsp; result := 0;<br>&nbsp; Printer:=TPrinter.Create;<br>&nbsp; PNeeded := AllocMem(8024); //分配内存空间<br>&nbsp; P2 := AllocMem(8048);<br>&nbsp; PPI := AllocMem(8048); //接受打印机信息结构<br>&nbsp; try<br>&nbsp; &nbsp; Printer.GetPrinter(Device, Driver, Port, DevMode); //取得打印机的名称,驱动程序,端口号<br>&nbsp; &nbsp; if not OpenPrinter(@device, hPrinter, nil) then &nbsp;begin<br>&nbsp; &nbsp; &nbsp; ErrMsg:='OpenPrinter' + SysErrorMessage(GetLastError);<br>&nbsp; &nbsp; &nbsp; Result:=-1;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; if not GetPrinter(hPrinter, 2, PPI, 8048, PNeeded) then &nbsp;begin<br>&nbsp; &nbsp; &nbsp; //取得打印机队列中的任务数<br>&nbsp; &nbsp; &nbsp; ErrMsg:='GetPrinter' + SysErrorMessage(GetLastError);<br>&nbsp; &nbsp; &nbsp; Result:=-1;<br>&nbsp; &nbsp; end; //取得打印机状态<br>&nbsp; &nbsp; if Enumjobs(hPrinter, 0, 1, 2, p2, 8048, Needed, Returned) then &nbsp;begin<br>&nbsp; &nbsp; &nbsp; if P2.JobId = 0 then &nbsp;result := 0;<br>&nbsp; &nbsp; &nbsp; if P2.JobId &gt; 0 then &nbsp;result := PPI.cJobs;<br>&nbsp; &nbsp; end else begin<br>&nbsp; &nbsp; &nbsp; ErrMsg:='Enumjobs' + SysErrorMessage(GetLastError);<br>&nbsp; &nbsp; &nbsp; Result:=-1;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; //关闭打印机,释放内存空间<br>&nbsp; finally<br>&nbsp; &nbsp; FreeMem(PNeeded);<br>&nbsp; &nbsp; FreeMem(p2);<br>&nbsp; &nbsp; FreeMem(PPI);<br>&nbsp; &nbsp; Printer.Free;<br>&nbsp; &nbsp; ClosePrinter(hPrinter);<br>&nbsp; end;<br>end;
 
procedure GetPrtDataRecParaValue(aCanvas:TCanvas); &nbsp; &nbsp; &nbsp;//获取打印参数信息<br>var<br>&nbsp; wx,wy:Integer;<br>begin<br>&nbsp; wx:=GetDeviceCaps(aCanvas.Handle,LOGPIXELSX );<br>&nbsp; wy:=GetDeviceCaps(aCanvas.Handle,LOGPIXELSY );<br>&nbsp; PrtDataRec.HorPix:=wx / 25.4;<br>&nbsp; PrtDataRec.VerPix:=wy / 25.4;<br>&nbsp; PrtDataRec.FontPix:=wx;<br>end;<br><br><br>function &nbsp;CheckInStallPrinter:Boolean; //检查是否安装有打印机<br>begin<br>&nbsp; Result:=Printer.Printers.Count&gt;0;<br>&nbsp; if not AppVar.Debug then Result:=True;<br>end;
 
关键时如何清除打印机任务
 
后退
顶部