procedure Tform1.UpdatePrint(Awidth,Aheight:integer);
const CustomFormName = 'ZJ Defined'; function Win95SetForm(PDevMode: PDeviceMode): Boolean;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERSIZE;
PDevMode.dmPaperSize := 256;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERWIDTH;
PDevMode.dmPaperWidth := AWidth;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERLENGTH;
PDevMode.dmPaperLength := AHeight;
Printer.PrinterIndex := Printer.PrinterIndex;
Result := True;
end; function WinNTSetForm(PDevMode: PDeviceMode;
Device: PChar; Port: PChar): Boolean;
var
hPrinter: THandle;
pForm: Pointer;
cbNeeded: DWORD;
cReturned: DWORD;
FormInfo1: TFormInfo1;
begin
Result := False;
if OpenPrinter(Device, hPrinter, nil) then
begin
pForm := nil;
EnumForms(hPrinter, 1, pForm, 0, cbNeeded, cReturned);
GetMem(pForm, cbNeeded); //取pForm的大小并分配内存
try
if EnumForms(hPrinter, 1, pForm, cbNeeded, cbNeeded, cReturned) then
begin
if DeleteForm(hPrinter, PChar(CustomFormName)) then
Dec(cReturned); //删除旧的Form
with FormInfo1 do
begin
Flags := 0;
pName := PChar(CustomFormName);
Size.cx := AWidth * 100;
Size.cy := AHeight * 100;
with ImageAbleArea do
begin
Left := 0;
Top := 0;
Right := Size.cx;
Bottom := Size.cy;
end;
end;
if AddForm(hPrinter, 1, @FormInfo1) then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERSIZE;
PDevMode.dmPaperSize := cReturned + 1;
Printer.PrinterIndex := Printer.PrinterIndex;
Result := True;
end;
end;
finally
FreeMem(pForm);
end;
end;
end;
var
Device, Driver, Port: array[0..127] of char;
hDevMode: THandle;
PDevMode: PDeviceMode;
begin
Printer.GetPrinter(Device, Driver, Port, hDevMode);
if hDevMode <> 0 then
begin
PDevMode := GlobalLock(hDevMode);
try
if (Win32Platform = VER_PLATFORM_WIN32s) or
(Win32Platform = VER_PLATFORM_WIN32_WINDOWS) then
Win95SetForm(PDevMode)
else if Win32Platform = VER_PLATFORM_WIN32_NT then
WinNTSetForm(PDevMode, Device, Port);
finally
GlobalUnlock(hDevMode);
end;
end
end;procedure TForm1.Button1Click(Sender: TObject);
begin
UpdatePrint(240,120)
end;
上述代码在AddForm这里运行是TRUE的,照理说应该是添加纸张成功,但是到打印机设置里面去找,却没找到我自定义的纸张。在打印机属性里去添加,倒是可以加进去的,但程序自动添加就是不能实现,不知道是什么问题,请大家想想办法
我是WINXP SP3的OS,打印机hp LaserJet 1010
const CustomFormName = 'ZJ Defined'; function Win95SetForm(PDevMode: PDeviceMode): Boolean;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERSIZE;
PDevMode.dmPaperSize := 256;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERWIDTH;
PDevMode.dmPaperWidth := AWidth;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERLENGTH;
PDevMode.dmPaperLength := AHeight;
Printer.PrinterIndex := Printer.PrinterIndex;
Result := True;
end; function WinNTSetForm(PDevMode: PDeviceMode;
Device: PChar; Port: PChar): Boolean;
var
hPrinter: THandle;
pForm: Pointer;
cbNeeded: DWORD;
cReturned: DWORD;
FormInfo1: TFormInfo1;
begin
Result := False;
if OpenPrinter(Device, hPrinter, nil) then
begin
pForm := nil;
EnumForms(hPrinter, 1, pForm, 0, cbNeeded, cReturned);
GetMem(pForm, cbNeeded); //取pForm的大小并分配内存
try
if EnumForms(hPrinter, 1, pForm, cbNeeded, cbNeeded, cReturned) then
begin
if DeleteForm(hPrinter, PChar(CustomFormName)) then
Dec(cReturned); //删除旧的Form
with FormInfo1 do
begin
Flags := 0;
pName := PChar(CustomFormName);
Size.cx := AWidth * 100;
Size.cy := AHeight * 100;
with ImageAbleArea do
begin
Left := 0;
Top := 0;
Right := Size.cx;
Bottom := Size.cy;
end;
end;
if AddForm(hPrinter, 1, @FormInfo1) then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
PDevMode.dmFields := PDevMode.dmFields or DM_PAPERSIZE;
PDevMode.dmPaperSize := cReturned + 1;
Printer.PrinterIndex := Printer.PrinterIndex;
Result := True;
end;
end;
finally
FreeMem(pForm);
end;
end;
end;
var
Device, Driver, Port: array[0..127] of char;
hDevMode: THandle;
PDevMode: PDeviceMode;
begin
Printer.GetPrinter(Device, Driver, Port, hDevMode);
if hDevMode <> 0 then
begin
PDevMode := GlobalLock(hDevMode);
try
if (Win32Platform = VER_PLATFORM_WIN32s) or
(Win32Platform = VER_PLATFORM_WIN32_WINDOWS) then
Win95SetForm(PDevMode)
else if Win32Platform = VER_PLATFORM_WIN32_NT then
WinNTSetForm(PDevMode, Device, Port);
finally
GlobalUnlock(hDevMode);
end;
end
end;procedure TForm1.Button1Click(Sender: TObject);
begin
UpdatePrint(240,120)
end;
上述代码在AddForm这里运行是TRUE的,照理说应该是添加纸张成功,但是到打印机设置里面去找,却没找到我自定义的纸张。在打印机属性里去添加,倒是可以加进去的,但程序自动添加就是不能实现,不知道是什么问题,请大家想想办法
我是WINXP SP3的OS,打印机hp LaserJet 1010
解决方案 »
- 执行onDoubleClick事件时,同时引起了onMouseDown事件,该如何处理。
- 再有一个SCPOMM的问题,为什么我的接收缓存器Buffer的数据,不会自动清除呢?
- 问题:如何窗体大小等于打印纸大小
- EXCEL导入到SQL SERVER的问题!
- 大家好!请问installshied是通用的还是有一种专给delphi用的!
- [讨论]如何优化Delphi代码?
- delphi Assgin() 应用.
- ★★★★关于case语句的问题★★★★
- 关于两台服务器时间比较的问题
- 有关串行口的编程.
- 有谁知道,如何读取波形文件.wav,然后做傅立叶变换后和模版声音数据进行模糊比较,VC 或着delphi
- 在DLL中用GETMEM 申请的内存,在调用完DLL后会不会自动释放??
∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞力争成为中国最大的架构师群联盟,架构师技术交流群:28995710已接近尾声,62402336正式开放!!!已经上传的顶级软件产品的架构分析,本群资料仅供研究学习,不得商用!!!
google 、
eBay、
Youtube、
淘宝等
......
技术文章包括:
《自己动手写操作系统》
《搜索引擎-原理、技术与系统》
《企业应用架构模式》
......
重要的RUP实例
设计模式精解
......
资料陆续上传中
∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞∽∝∞