Author: Tomas Rutkauskas
How to identify the paper names of the active printer
Answer:
1
2 procedure TFReport.GetPapernames(sl: TStrings);
3 type
4 TPaperName = array[0..63] of Char;
5 TPaperNameArray = array[1..High(Integer) div Sizeof(TPaperName)] of TPaperName;
6 PPapernameArray = ^TPaperNameArray;
7 var
8 Device, Driver, Port: array[0..255] of Char;
9 hDevMode: THandle;
10 i, numPaperformats: Integer;
11 pPaperFormats: PPapernameArray;
12 begin
13 Printer.GetPrinter(Device, Driver, Port, hDevmode);
14 numPaperformats := WinSpool.DeviceCapabilities(Device, Port, DC_PAPERNAMES, nil,
15 nil);
16 if numPaperformats > 0 then
17 begin
18 GetMem(pPaperformats, numPaperformats * Sizeof(TPapername));
19 try
20 WinSpool.DeviceCapabilities(Device, Port, DC_PAPERNAMES,
21 Pchar(pPaperFormats), nil);
22 sl.Clear;
23 for i := 1 to numPaperformats do
24 sl.add(pPaperformats^[i]);
25 finally
26 FreeMem(pPaperformats);
27 end;
28 end;
29 end;
|