在WIN2000/XP下添加自定义纸张
在Windows2000/XP/2003等系统中的自定义纸张的编号已经不是WIN98中256了,而是采用了一种新的标注方式,这里提供一个在Windows2000/XP/2003等系统中创建自定义纸张的函数,可以在套打编程中用到.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
//增加规格自定义纸张 //PaperName: 自定义纸张名称 //PaperWidth: 纸张的宽度,以0.1mm为单位 //PaperLength: 纸张的高度,以0.1mm为单位 procedure TDM.AddCustomPaper(const PaperName: string; PaperWidth, PaperLength:integer); var PrintDevice, PrintDriver, PrintPort : array[0..255] of Char; hDMode : THandle; hPrinter : THandle; FormInfo : TFormInfo1; begin Printer.GetPrinter(PrintDevice, PrintDriver, PrintPort, hDMode); OpenPrinter(PrintDevice, hPrinter, nil); if hPrinter = 0 then raise Exception.Create('联接打印机失败!'); with FormInfo do begin Flags := FORM_USER; pName := PChar(PaperName); Size.cx := PaperWidth*100; Size.cy := PaperLength*100; ImageableArea.Left := 0; ImageableArea.Top := 0; ImageableArea.Right := PaperWidth*100; ImageableArea.Bottom := PaperLength*100; end; //修改纸型,如果没有就新增 if not SetForm(hPrinter, PChar(PaperName), 1, @FormInfo) then AddForm(hPrinter, 1, @FormInfo); ClosePrinter(hPrinter); end; //删除自定义规格纸张 //PaperName: 自定义纸张名称 procedure TDM.DeleteCustomPaper(const PaperName: string); var PrintDevice, PrintDriver, PrintPort : array[0..255] of Char; hDMode : THandle; hPrinter : THandle; begin Printer.GetPrinter(PrintDevice, PrintDriver, PrintPort, hDMode); OpenPrinter(PrintDevice, hPrinter, nil); if hPrinter = 0 then raise Exception.Create('联接打印机失败!'); DeleteForm(hPrinter, PChar(PaperName)); ClosePrinter(hPrinter); end; |