Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Impresión (https://www.clubdelphi.com/foros/forumdisplay.php?f=4)
-   -   control de la cola de impresión (https://www.clubdelphi.com/foros/showthread.php?t=30593)

jun2008 10-04-2006 23:39:31

control de la cola de impresión
 
Hola a todos. Estoy intentando controlar la impresión que hace una aplicación de terceros, cuyo código, lógicamente, no puedo editar. Mi intención es poder imprimir, en una impresora matricial EPSON LQ 2180, página a página, haciendo una pausa en cada una de las páginas y mostrando una ventana en que se pueda elegir si continuar la impresión o cancelarla (antiguamente con los controladores para win98 de dicha impresora no había ningún problema en lograr tal cosa, pero con windows xp la cosa cambia). Hasta ahora lo que logro es hacer una pausa en la impresión, con el siguiente código:

Código Delphi [-]
procedure TMonitorImpresion.Timer1Timer(Sender: TObject);
var
  hPrinter: THandle;
  bytesNeeded, numJobs, i: Cardinal;
  //pJ: PJobs;
  pJ: array [0..1000] of JOB_INFO_2;
  cbBuf: DWORD;
  EstadoImpresora: DWORD;
begin
  cbBuf := 1000;
  hPrinter := GetCurrentPrinterHandle;

  EnumJobs(hPrinter, 0, 1000, 2, nil, 0, bytesNeeded, numJobs);

  if not EnumJobs(hPrinter, 0, Length(pJ), 1, @pJ, cbBuf, bytesNeeded, numJobs) then
    RaiseLastWin32Error;

  //EstadoImpresora := GetCurrentPrinterStatus;

  if numJobs = 0 then
  begin
    StringGrid1.Cells[1,1] := 'No hay trabajos en cola';
    StringGrid1.Refresh;
  end
  else
  //creamos más filas
  begin
    StringGrid1.RowCount := Pred(numJobs) + 2;
    for i := 0 to Pred(numJobs) do
    begin
      StringGrid1.Cells[0,i+1] := SavePChar(pJ[i].pPrinterName);
      StringGrid1.Cells[1,i+1] := SavePChar(pJ[i].pDocument);
      StringGrid1.Cells[2,i+1] := IntToStr(pJ[i].PagesPrinted);
      StringGrid1.Cells[3,i+1] := IntToStr(pJ[i].TotalPages);
      Case GetCurrentPrinterStatus of
        PRINTER_STATUS_PAUSED: Estado.Caption := 'Paused';
        PRINTER_STATUS_ERROR: Estado.Caption := 'Error';
        PRINTER_STATUS_PENDING_DELETION: Estado.Caption := 'Deleting...';
        PRINTER_STATUS_PAPER_JAM: Estado.Caption := 'Paper Jam';
        PRINTER_STATUS_PAPER_OUT: Estado.Caption := 'Paper Out';
        PRINTER_STATUS_MANUAL_FEED: Estado.Caption := 'Manual Feed Required';
        PRINTER_STATUS_PAPER_PROBLEM: Estado.Caption := 'Paper Problem';
        PRINTER_STATUS_OFFLINE: Estado.Caption := 'Offline';
        PRINTER_STATUS_IO_ACTIVE: Estado.Caption := 'Downloading Job';
        PRINTER_STATUS_BUSY: Estado.Caption := 'Busy';
        PRINTER_STATUS_PRINTING: Estado.Caption := 'Printing';
        PRINTER_STATUS_OUTPUT_BIN_FULL: Estado.Caption := 'Output Bill Full';
        PRINTER_STATUS_NOT_AVAILABLE: Estado.Caption := 'Not Available';
        PRINTER_STATUS_WAITING: Estado.Caption := 'Waiting';
        PRINTER_STATUS_PROCESSING: Estado.Caption := 'Processing Job';
        PRINTER_STATUS_INITIALIZING: Estado.Caption := 'Initializing';
        PRINTER_STATUS_WARMING_UP: Estado.Caption := 'Warming Up';
        PRINTER_STATUS_TONER_LOW: Estado.Caption := 'Toner Low';
        PRINTER_STATUS_NO_TONER: Estado.Caption := 'Toner Out';
        PRINTER_STATUS_PAGE_PUNT: Estado.Caption := 'Page too Complex';
        PRINTER_STATUS_USER_INTERVENTION: Estado.Caption := 'User Intervention Required';
        PRINTER_STATUS_OUT_OF_MEMORY: Estado.Caption := 'Out of Memory';
        PRINTER_STATUS_DOOR_OPEN: Estado.Caption := 'Door Open';
        PRINTER_STATUS_SERVER_UNKNOWN: Estado.Caption := 'Unable to connect';
        PRINTER_STATUS_POWER_SAVE: Estado.Caption := 'Power Save Mode';
      Else
        Estado.Caption := 'Estado de la Impresora Inespecífico';
      End
    end;

    If Ord(winspool.StartPagePrinter(hPrinter)) <> 0 then
      If EntrarMensage then
      begin
        EntrarMensage := False;
        EntrarMensage := MostrarMensage(hPrinter);
      end;
  end;
end;

Después la función mostrar mensaje:

Código Delphi [-]
function MostrarMensage(hPrinter: THandle): Boolean;
var
  n: word;
begin
  //winspool.setPrinter(hPrinter, 0, nil, PRINTER_CONTROL_PAUSE);
  winspool.setPrinter(hPrinter, 0, nil, JOB_CONTROL_PAUSE);
  If MessageDlg('Continuar con la impresión',
    mtInformation, [mbYes, mbNo], 0)= mrYes then
  begin
    winspool.setPrinter(hPrinter, 0, nil, JOB_CONTROL_RESUME);
    result := True;
  end
  else
  begin
    MonitorImpresion.PurgeJobsOnCurrentPrinter; {Purgar los trabajos de impresión}
    winspool.setPrinter(hPrinter, 0, nil, PRINTER_CONTROL_RESUME);
    result := True;
  end;

Pero no consigo más.

He mirado todas las funciones del API de windows para manejar la cola de impresión y la verdad, no se como lograrlo.

Muchas gracias a todos.


La franja horaria es GMT +2. Ahora son las 14:31:44.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi