PDA

Ver la Versión Completa : Estado de la impresora en windows xp


serhasae
27-10-2005, 14:01:52
Hola he estado mirando los hilos que hablan sobre saber el estado de una impresora, antes de imprimir y con lo que hay en los foros no me aclaro, ya que todos especifican pero ninguno da un ejemplo concreto que funcione.

A ver todo el mundo apunta a GetPrinter, he estado mirando una estructura nueva que sale para Nt o Xp que es el que se llama en SetPrinter, ya que Getprinter no la tiene. Supongo que habria que usar GetPrinter, luego SetPrinter y una vez la tengas poder mirar el estado de la impresora con el registro siguiente, pero voy algo perdido, alguna sugerencia o codigo que funcione. Gracias. Saludos.


typedef struct _PRINTER_INFO_6 {

DWORD dwStatus;

} PRINTER_INFO_6;





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



Value Meaning

PRINTER_STATUS_BUSY The printer is busy.

PRINTER_STATUS_DOOR_OPEN The printer door is open.

PRINTER_STATUS_ERROR The printer is in an error state.

PRINTER_STATUS_INITIALIZING The printer is initializing.

PRINTER_STATUS_IO_ACTIVE The printer is in an active input/output state

PRINTER_STATUS_MANUAL_FEED The printer is in a manual feed state.

PRINTER_STATUS_NO_TONER The printer is out of toner.

PRINTER_STATUS_NOT_AVAILABLE The printer is not available for printing.

PRINTER_STATUS_OFFLINE The printer is offline.

PRINTER_STATUS_OUT_OF_MEMORY The printer has run out of memory.

PRINTER_STATUS_OUTPUT_BIN_FULL The printer's output bin is full.

PRINTER_STATUS_PAGE_PUNT The printer cannot print the current page.

PRINTER_STATUS_PAPER_JAM Paper is jammed in the printer

PRINTER_STATUS_PAPER_OUT The printer is out of paper.

PRINTER_STATUS_PAPER_PROBLEM The printer has a paper problem.

PRINTER_STATUS_PAUSED The printer is paused.

PRINTER_STATUS_PENDING_DELETION The printer is deleting a print job.

PRINTER_STATUS_PRINTING The printer is printing.

PRINTER_STATUS_PROCESSING The printer is processing a print job.

PRINTER_STATUS_TONER_LOW The printer is low on toner.

PRINTER_STATUS_UNAVAILABLE The printer is not available for printing.

PRINTER_STATUS_USER_INTERVENTION The user needs to do something to the printer.

PRINTER_STATUS_WAITING The printer is waiting.

PRINTER_STATUS_WARMING_UP The printer is warming up.

delphi.com.ar
27-10-2005, 14:57:11
Te traduje un código que utilizo en otro lenguaje, a ver si te sirve:

unit SpoolUtils;

interface

uses
Windows;

function GetPrinterStatus(APrinterName: PChar): DWORD;

implementation

uses
Printers, WinSpool, SysUtils;

function GetPrinterStatus(APrinterName: PChar): DWORD;
var
HPrinter: THandle;
BytesNeeded: Cardinal;
PrinterDefaults: PRINTER_DEFAULTS;
PI2: ^PRINTER_INFO_2;
begin
with PrinterDefaults do
begin
DesiredAccess := PRINTER_ACCESS_USE;
pDatatype := nil;
pDevMode := nil;
end;

Win32Check(OpenPrinter(APrinterName, HPrinter, @PrinterDefaults));
try
if not GetPrinter(HPrinter, 2, nil, 0, @BytesNeeded) then
begin
GetMem(PI2, BytesNeeded);
try
if GetPrinter(HPrinter, 2, PI2, BytesNeeded, @BytesNeeded) then
Result := PI2^.Status
else
Result := MaxWord;
finally
FreeMem(PI2);
end;
end
else
Result := MaxWord;
finally
ClosePrinter(HPrinter);
end;
end;

end.

Saludos!

serhasae
27-10-2005, 15:07:21
A ver explicame un par de cosas, tendre que pasarle el nombre de la impresora a la funcion y me devulve un numero que indica el estado?, o se puede indicar la impresora activa con alguna funcion. la he probado y siempre me devuelve 0. Donde miro los numeros a los que se refiere el estado. Gracias.

delphi.com.ar
27-10-2005, 15:24:37
A ver explicame un par de cosas, tendre que pasarle el nombre de la impresora a la funcion y me devulve un numero que indica el estado?, o se puede indicar la impresora activa con alguna funcion. la he probado y siempre me devuelve 0.
No la puedo probar, yo utilizo un código similar en VB para saber si la impresora esta ocupada (aunque además averiguo si no hay trabajos en cola), y me ha funcionado sin problemas.

Donde miro los numeros a los que se refiere el estado. Gracias.
Los resultados posibles son las constantes que pusiste en la pregunta. No te voy a poner una ayuda de lo que escribí, busca información sobre las apis que utilizo y trata de comprender el código. Lamento no poder ayudarte mas, espero que el código te sirva al menos para investigar!

Saludos!