用GetPrinter检测打印机状态(100分)

S

siking

Unregistered / Unconfirmed
GUEST, unregistred user!
var<br>&nbsp; pHandel:Cardinal;<br>&nbsp; pPrinterInfo:TPrinterInfo2;<br>&nbsp; cByteUsed:DWORD;<br>begin<br>&nbsp; fillchar(pPrinterInfo,sizeof(TPrinterInfo2),0);<br>&nbsp; if OpenPrinter(pchar(ComboBox1.Text),pHandel,nil) then<br>&nbsp; &nbsp; if GetPrinter(pHandel,2,@pPrinterInfo,sizeof(TPrinterInfo2),@cByteUsed) then<br>&nbsp; &nbsp; &nbsp; ShowMessage(IntToStr(pPrinterInfo.Status));<br>&nbsp; ClosePrinter(pHandel);<br>end;<br>&nbsp; GetPrinter老是返回false,不知参数应该怎么设置<br><br>BOOL GetPrinter(<br><br>&nbsp; &nbsp; HANDLE hPrinter, // handle to printer of interest <br>&nbsp; &nbsp; DWORD Level, // version of printer info data structure <br>&nbsp; &nbsp; LPBYTE pPrinter, // pointer to array of bytes that receives printerinfo.structure <br>&nbsp; &nbsp; DWORD cbBuf, // size, in bytes, of array of bytes <br>&nbsp; &nbsp; LPDWORD pcbNeeded // pointer to variable with count of bytes retrieved (or required) <br>&nbsp; &nbsp;);
 
下面这段也许有用<br>var<br>&nbsp; Jobs: array [FirstJob..LastJob] of TJobInfo1;<br>&nbsp; PrinterHandle, BytesNeeded, NumJobs: Cardinal;<br>begin<br>&nbsp; if OpenPrinter(PChar(PrinterName),PrinterHandle,nil) then<br>&nbsp; begin<br>&nbsp; &nbsp; if EnumJobs(PrinterHandle, FirstJob, LastJob+1, InfoLevel, @Jobs, SizeOf(Jobs), BytesNeeded, NumJobs) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if NumJobs &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if Jobs.Status and JOB_CONTROL_PAUSE = JOB_CONTROL_PAUSE then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;........<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; ClosePrinter(PrinterHandle);<br>&nbsp; end;<br>end;
 
这样要等到有打印发生时才能知道打印机状态<br>能不能在打印前就知道状态
 
问题益决绝,有需要的人可参考<br>var<br>&nbsp; PrnHandle:THandle;<br>&nbsp; PrinterName:String;<br>&nbsp; buf:array[0..8192] of char;<br>&nbsp; dwSize:DWord;<br>&nbsp; pInfo:pPrinterInfo2;<br>begin<br>&nbsp; PrinterName:=ComboBox1.Text;<br>&nbsp; if OpenPrinter(pchar(PrinterName),PrnHandle,nil) then<br>&nbsp; begin<br>&nbsp; &nbsp; if GetPrinter(PrnHandle,2,@buf,sizeof(buf),@dwSize) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; pInfo:=PPrinterInfo2(@buf);<br>&nbsp; &nbsp; &nbsp; pInfo.Status。。。。就是这个状态<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; ClosePrinter(PrnHandle);<br>end;
 

Similar threads

I
回复
0
查看
688
import
I
I
回复
0
查看
585
import
I
I
回复
0
查看
520
import
I
顶部