我想这么多款...,总有一款适合你
<br><br>var <br>pinfo: pPRINTERINFO2; <br>pprt,a: Cardinal; <br>b
DWORD; <br>begin <br>b:=allocmem(256); <br>pinfo:=AllocMem(1000); <br>if OpenPrinter('HP DJ 200',pprt,nil) then <br>begin <br>a:=1000; <br>if getprinter(pprt,2,pinfo,a,b) then <br>showmessage(pinfo.pPrinterName+' ststus:'+inttostr(pinfo.Status)); <br>ClosePrinter(pprt); <br>end; <br><br>freemem(b); <br>freemem(pinfo); <br>end; <br><br>PRINTER_INFO_2.Status : <br>Windows NT: <br>PRINTER_STATUS_PAUSED <br>PRINTER_STATUS_PENDING_DELETION <br>Windows 95: <br>PRINTER_STATUS_BUSY <br>PRINTER_STATUS_DOOR_OPEN <br>PRINTER_STATUS_ERROR <br>PRINTER_STATUS_INITIALIZING <br>PRINTER_STATUS_IO_ACTIVE <br>PRINTER_STATUS_MANUAL_FEED <br>PRINTER_STATUS_NO_TONER <br>PRINTER_STATUS_NOT_AVAILABLE <br>PRINTER_STATUS_OFFLINE <br>PRINTER_STATUS_OUT_OF_MEMORY <br>PRINTER_STATUS_OUTPUT_BIN_FULL <br>PRINTER_STATUS_PAGE_PUNT <br>PRINTER_STATUS_PAPER_JAM <br>PRINTER_STATUS_PAPER_OUT <br>PRINTER_STATUS_PAPER_PROBLEM <br>PRINTER_STATUS_PAUSED <br>PRINTER_STATUS_PENDING_DELETION <br>PRINTER_STATUS_PRINTING <br>PRINTER_STATUS_PROCESSING <br>PRINTER_STATUS_TONER_LOW <br>PRINTER_STATUS_UNAVAILABLE <br>PRINTER_STATUS_USER_INTERVENTION <br>PRINTER_STATUS_WAITING <br>PRINTER_STATUS_WARMING_UP <br>////////////////////////////////////////////////////////////////// <br>unit PrinterStatus; <br><br>interface <br><br>uses <br>Windows, Messages, WinProcs, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; <br><br><br>// TPrinterstatus <br>// Komponente zum Abfragen des aktuellen Druckerportstatus <br>// Programmiert 2000 von K. Otto <br>// funktioniert unter Win 9x, jedoch nicht unter Win NT <br>// --------------------------------- <br>// Status: Freeware incl. Sourcecode <br>// --------------------------------- <br>// Diese Komponente beruht auf einem Beitrag von Robert Vivrette <br>// f黵 "The unofficial Newsletter of Delphi Users" <br>// http://www.undu.com/articles/990228a.html <br><br>type <br>TPrinterStatus = class(TComponent) <br>private <br>{ Private-Deklarationen } <br>fStatus : Byte; <br>fLPT : Integer; <br>Function GetTimeOut : Boolean; <br>Function GetIOError : Boolean; <br>Function GetPrinterSelected : Boolean; <br>Function GetOutOfPaper : Boolean; <br>Function GetAcknowledgement : Boolean; <br>Function GetPrinterBusy : Boolean; <br>protected <br>{ Protected-Deklarationen } <br>public <br>{ Public-Deklarationen } <br>Procedure CheckPrinterStatus; // Liest den Druckerstatus der angegeben LPT-Schnittstelle <br>Constructor Create(AOwner : TComponent); Override; <br>Property TimeOut : Boolean Read GetTimeOut; <br>Property IOError : Boolean Read GetIOError; <br>Property PrinterSelected : Boolean Read GetPrinterSelected; <br>Property OutOfPaper : Boolean Read GetOutOfPaper; <br>Property Acknowledgement : Boolean Read GetAcknowledgement; <br>Property Busy : Boolean Read GetPrinterBusy; <br>published <br>{ Published-Deklarationen } <br>Property LPT : Integer Read fLPT Write fLPT; <br>end; <br><br>procedure Register; <br><br>implementation <br><br>procedure Register; <br>begin <br>RegisterComponents('Eigene', [TPrinterStatus]); <br>end; <br><br>Function TPrinterStatus.GetTimeOut : Boolean; <br>Begin <br>Result:=(fStatus and $01)=$01; <br>End; <br><br>Function TPrinterStatus.GetIOError : Boolean; <br>Begin <br>Result:=(fStatus and $08)=$08; <br>End; <br><br>Function TPrinterStatus.GetPrinterSelected : Boolean; <br>Begin <br>Result:=(fStatus and $10)=$10; <br>End; <br><br>Function TPrinterStatus.GetOutOfPaper : Boolean; <br>Begin <br>Result:=(fStatus and $20)=$20; <br>End; <br><br>Function TPrinterStatus.GetAcknowledgement : Boolean; <br>Begin <br>Result:=(fStatus and $40)=$40; <br>End; <br><br>Function TPrinterStatus.GetPrinterBusy : Boolean; <br>Begin <br>Result:=not ((fStatus and $80)=$80); <br>End; <br><br>Procedure TPrinterStatus.CheckPrinterStatus; <br>Var <br>Status : Byte; <br>CheckLPT : Word; <br>Begin <br>Status:=0; <br>If (fLPT>=1) and (fLPT<=3) Then <br>Begin <br>CheckLPT:=fLPT-1; <br>asm <br>mov dx,CheckLPT; <br>mov al,0; <br>mov ah,2; <br>int 17h; <br>mov &Status, ah; <br>End; <br>End; <br>fStatus:=Status; <br>End; <br><br>Constructor TPrinterStatus.Create(AOwner : TComponent); <br>Begin <br>Inherited Create(AOwner); <br>fLPT:=1; <br>fStatus:=0; <br>End; <br><br>end. <br>////////////////////////////////////////////////////// <br>用法: <br><br>if not PrinterStatus1.PrinterReady(0) then //0 = current printerport <br>ShowMessage(PrinterStatus1.StatusMsg) else {print print print} ; <br><br>unit PrinterStatus; <br><br>interface <br><br>uses <br>Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; <br><br>type <br>TPrinterStatus = class(TComponent) <br>private <br>{ Private declarations } <br>FPort : Word; <br>FStatusStr : string; <br>protected <br>{ Protected declarations } <br>public <br>{ Public declarations } <br>function PrinterReady(LPT: Word): boolean; <br>published <br>{ Published declarations } <br>property StatusMsg: string read FStatusStr; <br>end; <br><br>procedure Register; <br><br>implementation <br>uses Printers; <br><br>procedure Register; <br>begin <br>RegisterComponents('Win95', [TPrinterStatus]); <br>end; <br><br>const <br>PrnReady = $90; <br>OffLine = $00; <br>OffLine2 = $10; {NEW LINE} <br>PaperOut = $20; <br>PaperOut2 = $30; {NEW LINE} <br>HookedButOff = $80; {NEW LINE} <br>NoConnect = $B0; {MODIFIED LINE} <br><br>{NOCONNECT = $30 FOR SOME COMPUTERS BY STU} <br><br>function TPrinterStatus.PrinterReady(LPT: Word): boolean; <br>var <br>ErrorCode, C : BYTE; <br>code, x : integer; <br>s : string; <br><br>function GetPrinterStatus (LPT: Word): Byte; <br>{Pass 1 in LPT for LPT1} <br>begin <br>asm <br>mov ah,2 <br>mov dx,LPT <br>dec dx <br>int $17 <br>mov @Result,ah <br>end; <br>end; {GetPrinterStatus} <br><br><br>begin <br>result := false; //assume not <br><br>FPort := LPT; <br>if FPort = 0 then begin {if no port specified then try to set port to current <br>printer port} <br>{printer name} <br>s := Printer.Printers[Printer.PrinterIndex]; <br>if Pos('FPort',s) <> 0 then begin <br>s := Copy(s, Pos('FPort',s) +3, 1); <br>Val(s,x,code); <br>if code <> 0 then FPort := 1 else FPort := x; <br>end else FPort := 1; {default to LPT1} <br>end; <br><br>{valid LPT is 1..4} <br>if (FPort > 4) or (FPort < 1) then begin <br>raise ERangeError.CreateFmt( <br>'LPT%d is not within the valid range of %d..%d', <br>[FPort, 1, 4]); <br>exit; <br>end; <br><br><br>ErrorCode := GetPrinterStatus(FPort); <br><br>ErrorCode := ErrorCode and $B0; {NEW LINE} <br><br>C := ERRORCODE shl 6; {ALWAYS MEANS NOTHING CONNECTED} <br><br>if C > 0 then ERRORCODE := $B0; {ELEMINATES NO LPT3 AND NOTHING CONNECTED} <br><br>case ErrorCode of <br>PrnReady : begin FStatusStr := 'Printer Ready'; result := true; <br>end; <br>NoConnect : FStatusStr := 'Printer not connected'; <br>Offline,OffLine2 : FStatusStr := 'Printer off line'; {Modified} <br>PaperOut,PaperOut2 : FStatusStr := 'Printer out of paper'; {Modified} <br>HookedButOff : FStatusStr := 'Printer connected but turned off'; {New} <br>else <br>FStatusStr := 'Printer error code: ' + IntToStr(ErrorCode); <br>end; <br><br>end; <br><br><br>end. <br><br>