function GetPrinterInfo5(Printer: THandle): PPrinterInfo5;
implementation
function GetPrinterInfo(Printer: THandle; Level: Integer):
Pointer;
var
BytesRequired: DWORD;
begin
{ Find out the required size of the structure }
GetPrinter(Printer, Level, nil, 0, @BytesRequired);
GetMem(Result, BytesRequired);
GetPrinter(Printer, Level, Result, BytesRequired,
@BytesRequired);
end;
function GetPrinterInfo5(Printer: THandle): PPrinterInfo5;
begin
Result := GetPrinterInfo(Printer,5);
end;
设置打印参数是要修改TDeviceMode结构同yjq说的一样
var
ADevice, ADriver, APort:array [0..255] of Char;
DeviceHandle:THandle;
DevMode:PDeviceMode;//TDeviceMode指针
begin
{首先获取TPrinter的DeviceMode结构的句柄}
PrinterGetPrinter(ADevice, ADriver, APort, DeviceHandle);
{如果句柄是0, 表示打印机没有装载}
if DeviceHandle=0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPritner(ADevice, ADriver, APort, DeviceHandle);
end;
{如果DeviceHandle还是0, 表示有错误发生。否则,就调用}
{GlobalLock来获取TDeviceMode结构的指针}
if DeviceHandle=0 then
Raise Exception.Create('Could Not Initialize TDeviceMode structure')
else
DevMode:=GlobalLock(DeviceHandle);
{下面是设置纸张大小}
with DevMode^ do
begin
dmFields:=dmFields or DM_PAPERSIZE;
dmPaperSize:=DMPADER_LETTER;//LETTER,8-1/2
{如果纸张大小由dmPaperWidth和dmPaperLength设置,则dmPaperSize的值可以设为0}
//dmFields:=dmFields or DM_PAPERLENGTH or DM_PAPERWIDTH;
//dmPaperLength:=somelength;
//dmPaperWidth:=somewidth;
end;
if not DeviceHandle=0 then
GlobalUnlock(DeviceHandle);
end;
关于TDeviceMode的详细情况参阅Win32 Programmer's Reference的DEVMODE主题