Author: Lou Adler
Needed routine to print output to a specific bin on a laser printer. The key to
this routine is the DevMode structure, there are several other routines that could
be written using this structure.
Answer:
1
2 procedure BinToPrintTo(BinNo: Integer);
3 var
4 ADevice, ADriver, APort: string;
5 ADeviceMode: THandle;
6 DevMode: PDeviceMode;
7 begin
8 SetLength(ADevice, 255);
9 SetLength(ADriver, 255);
10 SetLength(APort, 255);
11 if ADeviceMode = 0 then
12 begin
13 Printer.PrinterIndex := Printer.PrinterIndex;
14 Printer.GetPrinter(PChar(ADevice), PChar(ADriver),
15 PChar(APort), ADeviceMode);
16 end;
17 if ADeviceMode <> 0 then
18 begin
19 DevMode := GlobalLock(ADeviceMode);
20 try
21 DevMode^.dmDefaultSource := BinNo;
22 finally
23 GlobalUnlock(ADeviceMode);
24 end;
25 end
26 else
27 raise Exception.Create('Could not set printer copies');
28 end;
The functionality to Query the bin numbers. Setting the bin number must follow the
query of binnames and the assosiated number the following code is a brief sample
how it could be done.
29 var
30 iPaperTrayCount: Integer;
31 sBinNames: array of array[0..23] of Char;
32 iBinValues: array of Smallint;
33 iNumBins: Integer;
34 sPrinterDev: string;
35
36 begin
37 // Get the device name
38 sPrinterDev := TPrinterDevice(Printer.Printers.Objects[PrinterIndex]).Device;
39 // Query the number of Papaerbins
40 iNumBins := DeviceCapabilities(PChar sPrinterDev), '', DC_BINNAMES, nil, nil);
41
42 if iNumBins >= 0 then
43 begin
44 // Create an array that holds the name of the paper bin
45 // and a second to hold the needed Binnumbers
46
47 SetLength(sBinNames, iNumBins);
48 SetLength(iBinValues, iNumBins);
49
50 // get the names
51 DeviceCapabilities(PChar(sPrinterDev), nil, DC_BINNAMES, @sBinNames[0], nil);
52 // get the numbers
53 DeviceCapabilities(PChar(sPrinterDev), nil, DC_BINS, @iBinValues[0], nil);
54 end;
55 end;
|