用Printer对象进行打印时,如何判断打印机是否缺纸?(50分)

  • 主题发起人 主题发起人 lengtouxiaoer
  • 开始时间 开始时间
L

lengtouxiaoer

Unregistered / Unconfirmed
GUEST, unregistred user!
用Printer对象进行打印时,如何判断打印机是否缺纸?
 
用PrinterMessageBox这个API试一下
 
unit uPrinter;
interface
function CheckPrinter: boolean;
function GetPrinterStatus: byte;
implementation
//从并行端口读取打印机状态
function GetPrinterStatus: byte;
asm
MOV DX,$378;
IN AL,DX;
end;
//获取打印机是否出错
function CheckPrinter: boolean;
var
temp: byte;
begin
temp := GetPrinterStatus;
Result := not (((temp and $80) = 0) //打印机忙
or ((temp and $20) <> 0) //打印机缺纸
or ((temp and $10) = 0) //打印机未联机
or ((temp and $08) = 0));
//打印机出错;
end;

end.

WIN98下可以用 WIN2K不能用
 
取PrinterMessageBox的Error参数
是ERROR_OUT_OF_PAPER 说明缺纸
 
注释 监视打印机状态的控件 -- 作者:

开发语言: Delphi &amp;
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.
 
上面的方法好象不行!
 
后退
顶部