Приветствую, уважаемые форумчане!
После тщетных 5-и дневных поисков в сети, решил обратиться сюда.
Суть проблемы: нужно узнать текущее состояние LPT-принтера, OS WinXP. Тоесть узнать "Идет печать", "Нет бумаги" и т.д.
Программа всегда возвращает состояние ноль. Не пойму почему. Проблема наблюдается у многих программистов, но решение нигде не могу найти.
Вариантов программы много есть, но все выдают статус ноль, не зависимо от реального состояния принтера.
Вот код:
PHP код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Printers, WinSpool, StdCtrls;
...
...
procedure TForm1.btn1Click(Sender: TObject);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hPrinter: THandle;
hDeviceMode: THandle;
pcbNeed,pcReturned: DWORD;
Buffer: Pointer;
begin
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
if not OpenPrinter(@Device, hPrinter, nil) then Exit;
GetPrinter(hPrinter, 2, nil,0,@pcbNeed);
GetMem(Buffer, pcbNeed);
if GetPrinter(hPrinter, 2, Buffer, pcbNeed, @pcbNeed) then
begin
if TPrinterInfo2A(Buffer^).pServerName <> nil then
ListBox1.items.add('pServerName='+TPrinterInfo2A(Buffer^).pServerName);
if TPrinterInfo2A(Buffer^).pPrinterName <> nil then
ListBox1.items.add('pPrinterName='+TPrinterInfo2A(Buffer^).pPrinterName);
if TPrinterInfo2A(Buffer^).pShareName <> nil then
ListBox1.items.add('pShareName='+TPrinterInfo2A(Buffer^).pShareName);
if TPrinterInfo2A(Buffer^).pComment <> nil then
ListBox1.items.add('pComment='+TPrinterInfo2A(Buffer^).pComment);
if TPrinterInfo2A(Buffer^).pLocation <> nil then
ListBox1.items.add('pLocation='+TPrinterInfo2A(Buffer^).pLocation);
if TPrinterInfo2A(Buffer^).pPortName <> nil then
ListBox1.items.add('pPortName='+TPrinterInfo2A(Buffer^).pPortName);
if TPrinterInfo2A(Buffer^).pDriverName <> nil then
ListBox1.items.add('pDriverName='+TPrinterInfo2A(Buffer^).pDriverName);
if TPrinterInfo2A(Buffer^).pSepFile <> nil then
ListBox1.items.add('pSepFile='+TPrinterInfo2A(Buffer^).pSepFile);
if TPrinterInfo2A(Buffer^).pPrintProcessor <> nil then
ListBox1.items.add('pPrintProcessor='+TPrinterInfo2A(Buffer^).pPrintProcessor);
if TPrinterInfo2A(Buffer^).pDatatype <> nil then
ListBox1.items.add('pDatatype='+TPrinterInfo2A(Buffer^).pDatatype);
if TPrinterInfo2A(Buffer^).pParameters <> nil then
ListBox1.items.add('pParameters='+TPrinterInfo2A(Buffer^).pParameters);
ListBox1.items.add('Attributes='+inttostr(TPrinterInfo2A(Buffer^).Attributes));
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_QUEUED = PRINTER_ATTRIBUTE_QUEUED then
ListBox1.items.add(' PRINTER_ATTRIBUTE_QUEUED');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_QUEUED = PRINTER_ATTRIBUTE_QUEUED then
ListBox1.items.add(' PRINTER_ATTRIBUTE_QUEUED');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_DIRECT = PRINTER_ATTRIBUTE_DIRECT then
ListBox1.items.add(' PRINTER_ATTRIBUTE_DIRECT');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_DEFAULT = PRINTER_ATTRIBUTE_DEFAULT then
ListBox1.items.add(' PRINTER_ATTRIBUTE_DEFAULT');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_SHARED = PRINTER_ATTRIBUTE_SHARED then
ListBox1.items.add(' PRINTER_ATTRIBUTE_SHARED');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_NETWORK = PRINTER_ATTRIBUTE_NETWORK then
ListBox1.items.add(' PRINTER_ATTRIBUTE_NETWORK');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_HIDDEN = PRINTER_ATTRIBUTE_HIDDEN then
ListBox1.items.add(' PRINTER_ATTRIBUTE_HIDDEN');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_LOCAL = PRINTER_ATTRIBUTE_LOCAL then
ListBox1.items.add(' PRINTER_ATTRIBUTE_LOCAL');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_ENABLE_DEVQ = PRINTER_ATTRIBUTE_ENABLE_DEVQ then
ListBox1.items.add(' PRINTER_ATTRIBUTE_ENABLE_DEVQ');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS = PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS then
ListBox1.items.add(' PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST = PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST then
ListBox1.items.add('PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_WORK_OFFLINE = PRINTER_ATTRIBUTE_WORK_OFFLINE then
ListBox1.items.add(' PRINTER_ATTRIBUTE_WORK_OFFLINE');
if TPrinterInfo2A(Buffer^).Attributes and PRINTER_ATTRIBUTE_ENABLE_BIDI = PRINTER_ATTRIBUTE_ENABLE_BIDI then
ListBox1.items.add(' PRINTER_ATTRIBUTE_ENABLE_BIDI');
ListBox1.items.add('Priority='+inttostr(TPrinterInfo2A(Buffer^).Priority));
ListBox1.items.add('DefaultPriority='+inttostr(TPrinterInfo2A(Buffer^).DefaultPriority));
ListBox1.items.add('StartTime='+inttostr(TPrinterInfo2A(Buffer^).StartTime));
ListBox1.items.add('UntilTime='+inttostr(TPrinterInfo2A(Buffer^).UntilTime));
ListBox1.items.add('Status='+inttostr(TPrinterInfo2A(Buffer^).Status));
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAUSED = PRINTER_STATUS_PAUSED then
ListBox1.items.add(' PRINTER_STATUS_PAUSED');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_ERROR = PRINTER_STATUS_ERROR then
ListBox1.items.add(' PRINTER_STATUS_ERROR');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PENDING_DELETION = PRINTER_STATUS_PENDING_DELETION then
ListBox1.items.add(' PRINTER_STATUS_PENDING_DELETION');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAPER_JAM = PRINTER_STATUS_PAPER_JAM then
ListBox1.items.add(' PRINTER_STATUS_PAPER_JAM');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAPER_OUT = PRINTER_STATUS_PAPER_OUT then
ListBox1.items.add(' PRINTER_STATUS_PAPER_OUT');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_MANUAL_FEED = PRINTER_STATUS_MANUAL_FEED then
ListBox1.items.add(' PRINTER_STATUS_MANUAL_FEED');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAPER_PROBLEM = PRINTER_STATUS_PAPER_PROBLEM then
ListBox1.items.add(' PRINTER_STATUS_PAPER_PROBLEM');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_OFFLINE = PRINTER_STATUS_OFFLINE then
ListBox1.items.add(' PRINTER_STATUS_OFFLINE');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_IO_ACTIVE = PRINTER_STATUS_IO_ACTIVE then
ListBox1.items.add(' PRINTER_STATUS_IO_ACTIVE');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_BUSY = PRINTER_STATUS_BUSY then
ListBox1.items.add(' PRINTER_STATUS_BUSY');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PRINTING = PRINTER_STATUS_PRINTING then
ListBox1.items.add(' PRINTER_STATUS_PRINTING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_OUTPUT_BIN_FULL = PRINTER_STATUS_OUTPUT_BIN_FULL then
ListBox1.items.add(' PRINTER_STATUS_OUTPUT_BIN_FULL');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_NOT_AVAILABLE = PRINTER_STATUS_NOT_AVAILABLE then
ListBox1.items.add(' PRINTER_STATUS_NOT_AVAILABLE');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_WAITING = PRINTER_STATUS_WAITING then
ListBox1.items.add(' PRINTER_STATUS_WAITING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PROCESSING = PRINTER_STATUS_PROCESSING then
ListBox1.items.add(' PRINTER_STATUS_PROCESSING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_INITIALIZING = PRINTER_STATUS_INITIALIZING then
ListBox1.items.add(' PRINTER_STATUS_INITIALIZING');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_WARMING_UP = PRINTER_STATUS_WARMING_UP then
ListBox1.items.add(' PRINTER_STATUS_WARMING_UP');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_TONER_LOW = PRINTER_STATUS_TONER_LOW then
ListBox1.items.add(' PRINTER_STATUS_TONER_LOW');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_NO_TONER = PRINTER_STATUS_NO_TONER then
ListBox1.items.add(' PRINTER_STATUS_NO_TONER');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_PAGE_PUNT = PRINTER_STATUS_PAGE_PUNT then
ListBox1.items.add(' PRINTER_STATUS_PAGE_PUNT');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_USER_INTERVENTION = PRINTER_STATUS_USER_INTERVENTION then
ListBox1.items.add(' PRINTER_STATUS_USER_INTERVENTION');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_OUT_OF_MEMORY = PRINTER_STATUS_OUT_OF_MEMORY then
ListBox1.items.add(' PRINTER_STATUS_OUT_OF_MEMORY');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_DOOR_OPEN = PRINTER_STATUS_DOOR_OPEN then
ListBox1.items.add(' PRINTER_STATUS_DOOR_OPEN');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_SERVER_UNKNOWN = PRINTER_STATUS_SERVER_UNKNOWN then
ListBox1.items.add(' PRINTER_STATUS_SERVER_UNKNOWN');
if TPrinterInfo2A(Buffer^).Status and PRINTER_STATUS_POWER_SAVE = PRINTER_STATUS_POWER_SAVE then
ListBox1.items.add(' PRINTER_STATUS_POWER_SAVE');
ListBox1.items.add('cJobs='+inttostr(TPrinterInfo2A(Buffer^).cJobs));
ListBox1.items.add('AveragePPM='+inttostr(TPrinterInfo2A(Buffer^).AveragePPM));
end;
FreeMem(Buffer, pcbNeed);
end;
end.
В листбоксе всегда "Status=0"
И далее все ифы "конец бумаги", "пауза", "идет печать", "ожидание" и т.д игногрируются. Тоесть просто в листбоксе не выводится текущая ошибка.
Извините если непонятно выражаюсь.
Все надежда на вас!