lglhsy:分怎样给你?
昨天测了一下,订货系统在win2k下运行,网络打印机在98下,打印机自定义纸张怎么样设置,都可以打印出订货系统中以定义好的纸张,而在98下运行订货系统时,无论写什么代码
都是按打印机的设置来打印(订货系统在w2k下开发)
不知道为什么?我试过很多代码,都不行。以下是一段:
procedure TOrderKeyInFrm.setprintpaper(const w,h:integer);//w:宽度 h:高度
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDMode : THandle;
PDMode : PDEVMODE;
reg:tregistry;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin
{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
pDMode^.dmPaperSize := DMPAPER_LEGAL;
{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth :=w;
pDMode^.dmPaperLength :=h;
{Set the bin to use,以下写到注册表中是为了永久改变打印机纸张,但在win2000下无效,我也想知道}
reg:=tregistry.create;
reg.rootkey:=hkey_local_machine;
reg.OpenKey('/system/currentcontrolset/control/print/printers/'+pdmode.dmDeviceName,false);
reg.WriteBinaryData('Default DevMode',pdmode^,pdmode^.dmsize+pdmode^.dmdriverextra);
reg.closekey;
reg.free;
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex;
end;