请教关于Delphi打印设置的问题 你在每次打印之前,先printer.PageWidth:=printer.PageHeight:=设定之后,才调用实际的打印函数/。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 procedure 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; endend; TFormInfo1如何定义?运行到此卡住啦!急盼指点!!尽可能通俗一些,我刚刚入门! zjqyb:太谢谢你啦!你解决了困扰我很久的难题!谢谢! WH_GETMESSAGE的一个HOOK小问题 在安装增强型状态条控件时发生的问题 看来不加分不行了,150分求助!!! 怎么在扫描图片后,转换成80*60大小,保存到数据库里 如何判断系统已经或没有安装SQL数据库?分数不够可以再加? 一个字符字段长度是200,在打印时,一行打不完,怎样才能让其在下一行自动打印? ERP和传统的MS系统的区别? 请教各位高人 有谁知道DBGridEh在哪里下载?(高分) 对象设计 如何设置TreeView中的图标? 进度条问题。请教各位
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;