⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 得到打印机状态.txt

📁 大量Delphi开发资料
💻 TXT
字号:
unit PrinterStatus;


interface


uses

  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;


type

  TPrinterStatus = class(TComponent)

  private

    { Private declarations }

    FPort : Word;

    FStatusStr : string;

  protected

    { Protected declarations }

  public

    { Public declarations }

    function PrinterReady(LPT: Word): boolean;

  published

    { Published declarations }

    property StatusMsg: string read FStatusStr;

  end;


procedure Register;


implementation

uses Printers;


procedure Register;

begin

  RegisterComponents('Win95', [TPrinterStatus]);

end;


const

  PrnReady = $90;

  OffLine = $00;

  OffLine2 = $10;             {NEW LINE}

  PaperOut = $20;

  PaperOut2 = $30;            {NEW LINE}

  HookedButOff = $80;         {NEW LINE}

  NoConnect = $B0;            {MODIFIED LINE}


  {NOCONNECT = $30 FOR SOME COMPUTERS BY STU}


function TPrinterStatus.PrinterReady(LPT: Word): boolean;

var

  ErrorCode, C : BYTE;

  code, x : integer;

  s : string;


           function GetPrinterStatus (LPT: Word): Byte;

           {Pass 1 in LPT for LPT1}

           begin

             asm

               mov ah,2

               mov dx,LPT

               dec dx

               int $17

               mov @Result,ah

             end;

           end;  {GetPrinterStatus}



begin

 result := false;  //assume not


 FPort := LPT;

 if FPort = 0 then begin  {if no port specified then try to set port to current

printer port}

   {printer name}

   s := Printer.Printers[Printer.PrinterIndex];

   if Pos('FPort',s) <> 0 then begin

     s := Copy(s, Pos('FPort',s) +3, 1);

     Val(s,x,code);

     if code <> 0 then FPort := 1 else FPort := x;

   end else FPort := 1;  {default to LPT1}

 end;


 {valid LPT is 1..4}

 if (FPort > 4) or (FPort < 1) then begin

   raise ERangeError.CreateFmt(

     'LPT%d is not within the valid range of %d..%d',

     [FPort, 1, 4]);

   exit;

 end;



 ErrorCode := GetPrinterStatus(FPort);


 ErrorCode := ErrorCode and $B0;       {NEW LINE}


 C := ERRORCODE shl 6;   {ALWAYS MEANS NOTHING CONNECTED}


 if C > 0 then ERRORCODE := $B0; {ELEMINATES NO LPT3 AND NOTHING CONNECTED}


 case ErrorCode of

  PrnReady            : begin FStatusStr := 'Printer Ready'; result := true;

end;

  NoConnect           : FStatusStr := 'Printer not connected';

  Offline,OffLine2    : FStatusStr := 'Printer off line';     {Modified}

  PaperOut,PaperOut2  : FStatusStr := 'Printer out of paper'; {Modified}

  HookedButOff        : FStatusStr := 'Printer connected but turned off'; {New}

 else

  FStatusStr := 'Printer error code: ' + IntToStr(ErrorCode);

 end;


end;



end.


***********************************************************************************

Example use:


 if not PrinterStatus1.PrinterReady(0) then  //0 = current printerport

  ShowMessage(PrinterStatus1.StatusMsg) else {print print print} ;




{ PrinterStatus unit


  TPrinterStatus    Chris Willig  1/15/99


  Code hacked together from SWAG

  

  ****************************************************************************


  SWAG WEB Site :  http://www.gdsoft.com/swag/swag.html

  SWAG FTP Site  :  ftp://gdsoft.com/pub/swag


  About SWAG :


  SWAG is a collection of source code and program examples for

  the PASCAL program language.   The material  has been donated

  by various PASCAL programmers from around the world, interested

  in the continued  advancement of one of the finest programming

  platforms available today.


  *****************************************************************************

}


unit PrinterStatus;


interface


uses

  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;


type

  TPrinterStatus = class(TComponent)

  private

    { Private declarations }

    FPort : Word;

    FStatusStr : string;

  protected

    { Protected declarations }

  public

    { Public declarations }

    function PrinterReady(LPT: Word): boolean;

  published

    { Published declarations }

    property StatusMsg: string read FStatusStr;

  end;


procedure Register;


implementation

uses Printers;


procedure Register;

begin

  RegisterComponents('Win95', [TPrinterStatus]);

end;


const

  PrnReady = $90;

  OffLine = $00;

  OffLine2 = $10;             {NEW LINE}

  PaperOut = $20;

  PaperOut2 = $30;            {NEW LINE}

  HookedButOff = $80;         {NEW LINE}

  NoConnect = $B0;            {MODIFIED LINE}


  {NOCONNECT = $30 FOR SOME COMPUTERS BY STU}


function TPrinterStatus.PrinterReady(LPT: Word): boolean;

var

  ErrorCode, C : BYTE;

  code, x : integer;

  s : string;


           function GetPrinterStatus (LPT: Word): Byte;

           {Pass 1 in LPT for LPT1}

           begin

             asm

               mov ah,2

               mov dx,LPT

               dec dx

               int $17

               mov @Result,ah

             end;

           end;  {GetPrinterStatus}



begin

 result := false;  //assume not


 FPort := LPT;

 if FPort = 0 then begin  {if no port specified then try to set port to current

printer port}

   {printer name}

   s := Printer.Printers[Printer.PrinterIndex];

   if Pos('FPort',s) <> 0 then begin

     s := Copy(s, Pos('FPort',s) +3, 1);

     Val(s,x,code);

     if code <> 0 then FPort := 1 else FPort := x;

   end else FPort := 1;  {default to LPT1}

 end;


 {valid LPT is 1..4}

 if (FPort > 4) or (FPort < 1) then begin

   raise ERangeError.CreateFmt(

     'LPT%d is not within the valid range of %d..%d',

     [FPort, 1, 4]);

   exit;

 end;



 ErrorCode := GetPrinterStatus(FPort);


 ErrorCode := ErrorCode and $B0;       {NEW LINE}


 C := ERRORCODE shl 6;   {ALWAYS MEANS NOTHING CONNECTED}


 if C > 0 then ERRORCODE := $B0; {ELEMINATES NO LPT3 AND NOTHING CONNECTED}


 case ErrorCode of

  PrnReady            : begin FStatusStr := 'Printer Ready'; result := true;

end;

  NoConnect           : FStatusStr := 'Printer not connected';

  Offline,OffLine2    : FStatusStr := 'Printer off line';     {Modified}

  PaperOut,PaperOut2  : FStatusStr := 'Printer out of paper'; {Modified}

  HookedButOff        : FStatusStr := 'Printer connected but turned off'; {New}

 else

  FStatusStr := 'Printer error code: ' + IntToStr(ErrorCode);

 end;


end;



end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -