Board index » delphi » printer trays

printer trays

Hi,

My problem is that I need to be able to read in all the available trays for
the printers I have currently installed in Windows.

Delphi will let me look at the list of printers I have installed when I use
the TPrinter.printers , but I can't figure out how to go a steap further and
bring up the properties of that printer

Any help would be much appreciated

Scott.

--
Scott Goligher
Software Engineer

NiSoft (UK) Limited
Nisoft House, Ravenhill Business Park, Ravenhill Road, Belfast, BT6 8AW
Tel: +44 (0) 28 90 50 7555, Fax: +44 (0) 28 90 50 7556
email: sgolig...@nisoft.co.uk
Internet: www.nisoft.co.uk

Thursday 20 January 2000

NiSoft, one of Northern Ireland's fastest growing software companies, today
released a new version of eclipse, their best selling Safety Document
Management System. The latest version incorporates the ability to provide
Tagged Isolations for safety documents in power stations as used widely in
Asia-Pacific and the USA, as an alternative to the Lock-Out Isolations used
in the UK. This will allow NiSoft customers around the world to benefit from
the ease of use of the eclipse product.

NiSoft also announced that eclipse will be launched in Asia-Pacific in
March, and a Chinese language version of eclipse is planned for later this
year.

 

Re:printer trays


Quote
Scott Goligher <sgolig...@nisoft.co.uk> wrote in message

news:32AA3B12B79DD311B0CB006097A4426B13D75C@ORION...

Quote
> My problem is that I need to be able to read in all the available trays
for
> the printers I have currently installed in Windows.

> Delphi will let me look at the list of printers I have installed when I
use
> the TPrinter.printers , but I can't figure out how to go a steap further
and
> bring up the properties of that printer

You need to get the name and port of each printer in turn, and pass them to
the DeviceCapabilities function.

Here's some code that might help...

  { Record to hold name, driver and port of printer. }
  TPrinterInfo = record
    Name:   array[0..80] of Char;
    Driver: array[0..80] of Char;
    Port:   array[0..80] of Char;
  end;

implementation

uses Winspool, Printers;

procedure GetPrinterInfo(Index: integer; var PrinterInfo: TPrinterInfo);
var
  hDMode : THandle;
begin
  Printer.PrinterIndex := Index;
  Printer.GetPrinter(PrinterInfo.Name, PrinterInfo.Driver, PrinterInfo.Port,
hDMode);
end;

function GetPrinterBins(PrinterInfo: TPrinterInfo): PChar;
const
  SizeOfBinName = 24;
var
  i, NoOfBins: Integer;
  P: PChar;
  List: TStringList;
begin
  List := TStringList.Create;
  NoOfBins := DeviceCapabilities(PrinterInfo.Name, PrinterInfo.Port,
    DC_BINNAMES, nil, nil);
  GetMem(P, SizeOfBinName * NoOfBins);
  try
    NoOfBins := DeviceCapabilities(PrinterInfo.Name, PrinterInfo.Port,
      DC_BINNAMES, P, nil);
    for i := 0 to NoOfBins - 1 do
      List.Add(P + (i * SizeOfBinName));
    Result := List.GetText;
  finally
    FreeMem(P);
    List.Free;
  end;
end;

Now do something like this...

var
  PrinterInfo: TPrinterInfo;
begin
  GetPrinterInfo(-1, PrinterInfo);    // -1 is default printer
  { Fill a combobox with the list of bins for this printer }
  ComboBox1.Items.SetText(GetPrinterBins(PrinterInfo));
end;

--
Stephen Brown

Other Threads