|
{X=2290,Y=2970 每次运行后打印机就定位到了Letter纸张,甚是郁闷,希望大家指点!!!}
procedure SetPaperSize(X, Y: Integer);
var
Device: array[0..255] of char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
hDMode: THandle;
PDMode: PDEVMODE;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device,Driver,Port,hDMode);
// 获取打印机DevMode 结构的句柄值,存放在hDMode 中
if hDMode<>0 then begin
pDMode := GlobalLock(hDMode);
// 获取指向打印机DevMode 结构的// 指针
if pDMode <> nil then begin
pDMode^.dmPaperSize := 256;
// 如果要将当前打印机纸张变为自定义,dmPaperSize 必须设置成256
pDMode^.dmPaperLength := X;
pDMode^.dmPaperWidth := Y;
pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE;
pDMode^.dmFields := pDMode^.dmFields or DM_PAPERLENGTH;
pDMode^.dmFields := pDMode^.dmFields or DM_PAPERWIDTH;
{以上三条语句是对相应的dmFields 成员进行置位。}
ResetDC(Printer.Handle,pDMode^);
// 设置打印机设备环境句柄的值
GlobalUnlock(hDMode);
//以下开始打印
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex;
end; |
|