枚举指定打印机上定义的纸张名称:
procedure GetPaperList(PrinterName: String;
PaperList: TStrings);
type
PPaperName = ^TPaperName;
TPaperName = array [0..0] of array [0..63] of char;
var
hPrinter: THandle;
pd: PRINTER_DEFAULTS;
Buf: Pointer;
pPaper: PPaperName;
dwNeeded, i: DWORD;
begin
PaperList.Clear;
pd.DesiredAccess := PRINTER_ALL_ACCESS;
pd.pDatatype := nil;
pd.pDevMode := nil;
// 打开打印机
if OpenPrinter(PChar(PrinterName),hPrinter,@pd) then
begin
dwNeeded := DeviceCapabilities(PChar(PrinterName), nil,
DC_PAPERNAMES, nil, nil);
if dwNeeded > 0 then
begin
GetMem(Buf, (dwNeeded + 1)* 64);
try
dwNeeded := DeviceCapabilities(PChar(PrinterName), nil,
DC_PAPERNAMES, Buf, nil);
pPaper := PPaperName(Buf);
for i := 0 to dwNeeded - 1do
begin
PaperList.Add(pPaper);
end;
finally
FreeMem( Buf );
end;
end;
end;
end;
示例:
// 取列表中打印机HP LaserJet 6P中定义的纸张名称
procedure TForm1.Button2Click(Sender: TObject);
begin
GetPaperList('HP LaserJet 6L', lbPaperList.Items )
end;