注释 监视打印机状态的控件 -- 作者:
开发语言: Delphi &
Kylix
简介: Win95/98 下用,只支持并口的。
文件大小: 1.816Kb
适合系统: Windows 9*/ME
{ 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 beendo
nated
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.