如何获得打印机的当前状态?(例如,缺纸、卡纸等)(50分)

  • 主题发起人 主题发起人 demonP
  • 开始时间 开始时间
D

demonP

Unregistered / Unconfirmed
GUEST, unregistred user!
为了获得默认打印机的当前状态(正在打印、缺纸等),
在DELPHI中使用了如下代码:

procedure TForm1.Button1Click(Sender: TObject);
var hprint:THandle;
sp:String;
tt:Pointer;
dd:DWord;
bb:boolean;
i:integer;
begin


sp:=copy(Printer.printers[printer.printerIndex],1,
pos(' on ',Printer.printers[printer.printerIndex])-1);
OpenPrinter(pchar(sp),hPrint,nil);

if getprinter(hprint,2,tt,0,pdword(@dd)) then

showmessage('True');
Getmem(tt, dd );
if getprinter(hprint,2,tt,dd,pdword(@dd)) then

showmessage('True');
i:=(Pprinterinfo2(tt)).status;
FreeMem(tt);
showmessage(inttostr(i));
ClosePrinter(hPrint);

end;


以上代码无语法错误,可以顺利执行。执行完GETPRINTER后,TT记录中
的各项(例如打印机名等)都能正确返回,但STATUS项始终是0。不知为何?
讨论区里有个同样的问题,我比较了一下,好象和我上面的
做法是一样的,真是不明白,请高手指点,急!谢谢!






 
function TestPrinterStatus(LPTPort: word): byte;

var
Status: byte;

CheckLPT: word;

begin

Status := 0;

if (LPTPort >= 1) and (LPTPort <= 3) then

begin

CheckLPT := LPTPort -1;

asm
mov dx, CheckLPT;

mov al, 0;

mov ah, 2;

int 17h;

mov &amp;Status, ah;

end;


end;


Result := Status;

end;


参数时打印机端口,返回值如下:
01h - Timeout
08h - I/O Error
10h - Printer selected
20h - Out of paper
40h - Printer acknowledgement
80h - Printer not busy (0 if busy)

 
谢谢您的答复,我试试!
不过除了这么“底层”的办法,就没有其它的
办法了么?
 
Keyes真厉害。
 
typedef struct _PRINTER_INFO_2 { // pri2
LPTSTR pServerName;

LPTSTR pPrinterName;

LPTSTR pShareName;

LPTSTR pPortName;

LPTSTR pDriverName;

LPTSTR pComment;

LPTSTR pLocation;

LPDEVMODE pDevMode;

LPTSTR pSepFile;

LPTSTR pPrintProcessor;

LPTSTR pDatatype;

LPTSTR pParameters;

PSECURITY_DESCRIPTOR pSecurityDescriptor;

DWORD Attributes;

DWORD Priority;


DWORD DefaultPriority;

DWORD StartTime;

DWORD UntilTime;

DWORD Status;

DWORD cJobs;

DWORD AveragePPM;

} PRINTER_INFO_2;



Status

Specifies the printer status. This member can be one of the following values:

Windows NT:

PRINTER_STATUS_PAUSED
PRINTER_STATUS_PENDING_DELETION

Windows 95:

PRINTER_STATUS_BUSY
PRINTER_STATUS_DOOR_OPEN
PRINTER_STATUS_ERROR
PRINTER_STATUS_INITIALIZING
PRINTER_STATUS_IO_ACTIVE
PRINTER_STATUS_MANUAL_FEED
PRINTER_STATUS_NO_TONER
PRINTER_STATUS_NOT_AVAILABLE
PRINTER_STATUS_OFFLINE
PRINTER_STATUS_OUT_OF_MEMORY
PRINTER_STATUS_OUTPUT_BIN_FULL
PRINTER_STATUS_PAGE_PUNT
PRINTER_STATUS_PAPER_JAM
PRINTER_STATUS_PAPER_OUT
PRINTER_STATUS_PAPER_PROBLEM
PRINTER_STATUS_PAUSED
PRINTER_STATUS_PENDING_DELETION
PRINTER_STATUS_PRINTING
PRINTER_STATUS_PROCESSING
PRINTER_STATUS_TONER_LOW
PRINTER_STATUS_UNAVAILABLE
PRINTER_STATUS_USER_INTERVENTION
PRINTER_STATUS_WAITING
PRINTER_STATUS_WARMING_UP
 
I want to know either!
 
谢谢各位的指点,我想现在基本上可以认为,除了
使用KEYES提供的ASM外,应该没有(至少目前)其它
方法直接得到打印机的状态。当然,可以用第一个打印
任务的状态来间接做到,但在无任务时就不能胜任了。

这就是该问题目前的最新进展,如果大家有了什么新
发现可以随时回来继续讨论。
谢谢,以后多交流。
 
Keyes :
确实厉害,不过只能在本地试,网络打印机怎么办?
 
后退
顶部