Показать сообщение отдельно
  #7  
Старый 16.05.2011, 13:46
kiman.ru kiman.ru вне форума
Новичок
 
Регистрация: 11.02.2010
Сообщения: 63
Репутация: 10
По умолчанию Код программы

Код:
procedure TForm1.Button1Click(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;

Procedure TForm1.ShowPrinterStatus( const PrinterName : String );
Var
PrinterInfo: PPrinterInfo2;
PrinterHandle : THandle;
Stat : LongBool;
requiredSize : Cardinal;

Begin
Try
Stat := OpenPrinter( PChar(PrinterName), PrinterHandle, NIL );
//This works fine

If ( Stat )
Then
Begin
Try
GetMem( PrinterInfo, 1024 );
Stat := GetPrinter(PrinterHandle, 2, PrinterInfo, 1024,
@requiredSize );
Edit2.Text := 'Printer Name Is: ' + PrinterInfo^.pPrinterName;
Form1.Caption := inttostr(PrinterInfo^.Attributes);
Case PrinterInfo^.Status of
0 : Edit1.Text := 'Printer Ready!';
PRINTER_STATUS_DOOR_OPEN : Edit1.Text := 'Door Open';
PRINTER_STATUS_POWER_SAVE : Edit1.Text := 'Power SaveMode';
PRINTER_STATUS_WARMING_UP : Edit1.Text := 'Warming Up';
PRINTER_STATUS_PAPER_OUT : Edit1.Text := 'Out of Paper';
End;
Finally
FreeMem( PrinterInfo, 1024 );
End;
End
Else
Begin
Edit1.Text := 'NA';
Edit2.Text := 'Cannot Open Printer: ' + PrinterName;
End;
Finally
ClosePrinter( PrinterHandle );
End;
End;
Ответить с цитированием