how to set paper custom size (再次问)(100分)

  • 主题发起人 主题发起人 arm
  • 开始时间 开始时间
A

arm

Unregistered / Unconfirmed
GUEST, unregistred user!
上次问的,结果没有人回答,这一段程序不好使
(不必告诉我PAPERSIZE=0, 使过了不好使)
PRINTER EPSON-1800K OR EPSON 1600-K
procedure SetPaperSize(X, Y: Integer);
var
Device, Driver, Port: PChar;
HDMode: THandle;
PDMode: PDevMode;
begin
Device := StrAlloc(cchDeviceName);
Driver := StrAlloc(MAX_PATH);
Port := StrAlloc(32);
try
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, HDMode);
if HDMode<>0 then
begin
PDMode := GlobalLock(HDMode);
if PDMode =nil then
begin
with PDMode^do
begin
dmPaperSize :=256;
dmPaperWidth :=X;
dmPaperLength :=Y;
dmFields :=DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
GlobalUnlock(HDMode);
end;
Printer.PrinterIndex := Printer.PrinterIndex;
end;
end;
finally
StrDispose(Device);
StrDispose(Driver);
StrDispose(Port);
end;
end;
 
你试试把 dmFields :=DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
改成 dmFields :=dmFields or DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
 

你试试把 dmFields :=DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
改成 dmFields :=dmFields or DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
不管用
 
procedure TForm1.Button1Click(Sender: TObject);
var
Device:Array[0..256] of Char;
Driver:Array[0..256] of Char;
Port:Array[0..32] of Char;
hDMode:THandle;
pDMode:PDevMode;
begin
Printer.GetPrinter(Device,Driver,Port,hDMode);
if hDMode<>0 then
pDMode:=GLobalLock(hDMode);
//////////////pDMode<>nil非pDMode=nil
if pDMode<>nil then
begin
pDMode^.dmPaperSize:=256;
pDMode^.dmPaperLength:=1140;
pDMode^.dmPaperWidth:=1900;
pDMode^.dmFields:=pDMode^.dmFields or DM_PAPERSIZE;
pDMode^.dmFields:=pDMode^.dmFields or DM_PAPERLENGTH;
pDMode^.dmFields:=pDMode^.dmFields or DM_PAPERWIDTH;
end;
ResetDC(Printer.Handle,pDMode^);
GLobalUnLock(hDMode);
end;
 
接受答案了.
 
后退
顶部