如何得到当前的打印机状态?(50分)

  • 主题发起人 主题发起人 liangXing
  • 开始时间 开始时间
什么状态?
 
检查 Printer.Printing 可以知道打印机是否正在打印。<br>检查 Printer.Printers 可以知道当前系统安装哪些了打印机。<br>如果用 Quick Report, 检查 QRPrinter.Status 或 <br>QRPrinter.PrinterOK 可知道打印机是否就绪。
 
* GetDeviceCaps<br><br>另外,要检查驱动程序内的设置,可以用<br>DeviceCapabilities
 
那如何判断打印过程中是否有卡纸、缺纸、打印机脱机等异常呢?<br>
 
1.是否有打印机可用<br>2.打印机是否连接好<br>3.是否有缺纸,卡纸等异常<br>
 
&nbsp;用两个API<br>1.BOOL OpenPrinter(<br><br>&nbsp; &nbsp; LPTSTR pPrinterName, // pointer to printer or server name <br>&nbsp; &nbsp; LPHANDLE phPrinter, // pointer to printer or server handle <br>&nbsp; &nbsp; LPPRINTER_DEFAULTS pDefault // pointer to printer defaults structure &nbsp;<br>&nbsp; &nbsp;); <br>&nbsp; &nbsp;得到打印机句饼;<br>2.BOOL GetPrinter(<br>HANDLE hPrinter,// handle to printer of interest <br>DWORD Level, // version of printer info data structure <br>//此处Level=2 &nbsp; &nbsp;<br>LPBYTE pPrinter,// pointer to array of bytes that receives printer info. structure <br>DWORD cbBuf, // size, in bytes, of array of bytes <br>LPDWORD pcbNeeded // pointer to variable with count of bytes retrieved (or required) <br>&nbsp; &nbsp;); <br>&nbsp; &nbsp;得到结构 pPrinter,可得到属性DWORD<br>
 
上回忘说了,还有closeprinter()
 
也可以用这个函数<br><br>BOOL EnumPrinters(<br>DWORD Flags, // types of printer objects to enumerate <br>LPTSTR Name, // name of printer object <br>DWORD Level, // specifies type of printer info structure <br>LPBYTE pPrinterEnum,// pointer to buffer to receive printer info structures <br>DWORD cbBuf, // size, in bytes, of array <br>LPDWORD pcbNeeded,// pointer to variable with no. of bytes copied (or required) <br>LPDWORD pcReturned // pointer to variable with no. of printer info. structures copied <br>&nbsp; &nbsp;); <br>&nbsp;
 
如果是Win9x平台,可用BIOS的INT 17h(用内嵌汇编),读回打印机的状态字节<br>加以分析。
 
LiangXing,到底明白了没有?不明白的地方欢迎继续讨论,<br>是不是该把分加一下了?我可正等着分用呢。:-)
 
多人接受答案了。
 
To SunSet:<br>&nbsp; SunSet大虾,<br>!.程序中 if &nbsp;QuickRep1.QRPrinter.PrinterOK then<br>程序编译没问题,但运行至此系统提示错误对话框<br>Access Violation at address 004A2890 in module 'PRN.EXE'.Read of address FFFFFFFF<br><br>2.QuickRep1.QRPrinter.Status;则直接编译不过<br>以上问题是什么原因?<br>
 
后退
顶部