如何给打印机添加自定义纸型,设置高和宽?(不是在控制面板而是写Delphi) ( 积分: 50 )

  • 主题发起人 主题发起人 gtln
  • 开始时间 开始时间
G

gtln

Unregistered / Unconfirmed
GUEST, unregistred user!
如何给打印机添加自定义纸型,设置高和宽?(不是在控制面板而是写Delphi)
 
如何给打印机添加自定义纸型,设置高和宽?(不是在控制面板而是写Delphi)
 
参考
http://www.delphibbs.com/delphibbs/DispQ.asp?LID=2472056
标题是: 如何给打印机添加一个自定义纸张类型?
-------------------------转自网络(app大虾的)
procedure PreparePrinter;
var
aDevice: array[0..CCHDEVICENAME-1] of Char;
aDriver: array[0..MAX_PATH-1] of Char;
aPort: array[0..31] of Char;
hDevMode: THandle;
pDevMode: PDeviceMode;
begin
// 获取打印机DeviceMode的句柄
Printer.GetPrinter(aDevice, aDriver, aPort, hDevMode);
if hDevMode <> 0 then
begin
// 获取指向DeviceMode的指针
pDevMode := GlobalLock(hDevMode);
if pDevMode <> nil then
begin
pDevMode^.dmPaperSize := DMPAPER_USER;
pDevMode^.dmPaperLength := 1140;
pDevMode^.dmPaperWidth := 1900;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERSIZE;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERLENGTH;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERWIDTH;
ResetDC(Printer.Handle, pDevMode^);
GlobalUnlock(hDevMode);
end;
end;
end;
 
我也贴
在WIN2000/XP下添加自定义纸张的Delphi源代码 选择自 yangliu 的 Blog
关键字 在WIN2000/XP下添加自定义纸张的Delphi源代码
出处

////////////////////////////
// 武汉探索电脑工作室 //
// http://tansuo.51.net //
////////////////////////////
//增加规格自定义纸张
//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 FormInfodo

 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;

作者Blog:http://blog.csdn.net/yangliu/
 
app2001您好 编译不了呵,能否指点迷津,给个例子?
 
TPrinterSetupDialog
 

Similar threads

后退
顶部