这个函数好用,不过winxp,2000,nt下不好用
function setprnpaper(const wdth,lenth:real):boolean;
var FDevice, FDriver, FPort:array [0..255] of char;
DeviceMode,HPrt:THandle;
DevMode
DeviceMode;
begin
result:=true;
Printer.GetPrinter(FDevice, FDriver, FPort, DeviceMode);
if DeviceMode<=0 then
begin
result:=false;
exit;
end;
DevMode := GlobalLock(DeviceMode);
OpenPrinter(FDevice, HPrt, nil);
begin
DevMode^.dmFields := DevMode^.dmFields or dm_paperlength;
DevMode^.dmPaperLength :=trunc(lenth*10);
DevMode^.dmFields := DevMode^.dmFields or dm_paperwidth;
DevMode^.dmPaperWidth :=trunc(wdth*10);
DevMode^.dmFields := DevMode^.dmFields or dm_papersize;
DevMode^.dmPaperSize := DMPAPER_USER;
end;
SetPrinter(HPrt,0,DevMode,PRINTER_CONTROL_SET_STATUS);
do
cumentProperties(DeviceMode,HPrt,FDevice,DevMode^,DevMode^,DM_IN_BUFFER or DM_UPDATE);
GlobalUnlock(DeviceMode);
ClosePrinter(HPrt);
end;