急,急,修改win98下面的自定义打印纸张的大小,请高手帮忙。(100分)

  • 主题发起人 主题发起人 可儿
  • 开始时间 开始时间

可儿

Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一段程序,用于修改win98下面的自定义打印纸张的大小,并将它设置为默认值,
可是结果并没有修改。
procedure TForm1.Button1Click(Sender: TObject);
var
adevice,adriver,aport:array[0..255] of char;
devicehandle:thandle;
devmode:pdevicemode;
begin

printer.getprinter(adevice,adriver,aport,devicehandle);
if devicehandle=0 then

begin

printer.printerindex:=printer.printerindex;
printer.getprinter(adevice,adriver,aport,devicehandle);
end;

if devicehandle=0 then

raise exception.create('打印机错误!')
else

begin

devmode:=globallock(devicehandle);
with devmode^do

begin

dmfields:=dmfields or dm_orientation;
dmorientation:=dmorient_portrait;
dmfields:=dmfields or dm_papersize;
dmpapersize:=256;
dmfields:=dmfields or dm_paperlength;
dmpaperlength:=2794;
dmfields:=dmfields or dm_paperwidth;
dmpaperwidth:=3500;
end;

ResetDC(Printer.Handle,devmode^);
globallock(devicehandle);
end;

end;

 
看看如下:
dmpapersize:= 0 ;
//必须为零
dmfields:=dmfields or dm_paperlength;
dmpaperlength:=2794;
dmfields:=dmfields or dm_paperwidth;
dmpaperwidth:=3500;
 
老兄这分可轮到我来拿了。
var
ADevice, ADriver, APort: array[0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin

//初始化打印机
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
if DeviceHandle = 0 then

begin

Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end;

if DeviceHandle = 0 then

Raise Exception.Create('不能初始化打印机!')
else

DevMode := GlobalLock(DeviceHandle);
if DeviceHandle <> 0 then

begin

GlobalUnLock(DeviceHandle);
with DevMode^do

begin

dmFields := dmFields or DM_PAPERWIDTH or DM_PAPERLENGTH;
dmPaperSize := DMPAPER_USER;
dmPaperWidth := 2940;
dmPaperLength := 3500;
Printer.SetPrinter(ADevice, ADriver, APort, DeviceHandle);
end;

if GetPaperWidth < 2939 then
//在此省略GetPaperWidth函数
MessageBox(Handle,'系统默认打印机的打印尺寸不能满足本打印任务的需要!'+#13+#13
+'请使用符合要求的打印机, 并安装正确的打印驱动程序。','打印机不兼容',
MB_ICONWARNING+MB_OK);
end;

end;

 
接受答案了.
 
后退
顶部