请教! (50分)

  • 主题发起人 主题发起人 编程初学者
  • 开始时间 开始时间

编程初学者

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手帮帮忙啊
怎么样自定义纸张大小,然后在纸张指定的位置打印文本?
主要是怎么样控制文字输出的实际位置啊(精确位置!!!)
 
FDevice : PChar;
FDriver : PChar;
FPort : PChar;
DeviceMode : THandle;
DevMode : PDeviceMode;
constructor TPrinterSettings.Create;
begin
inherited Create;
GetMem(FDevice, 128);
GetMem(FDriver, 128);
GetMem(FPort, 128);
FPaperSize := A4;
FPrinter := nil;
end;

function TPrinterSettings.Supported(Setting : integer) : boolean;
begin
if assigned(FPrinter) then
Supported := (DevMode^.dmFields and Setting) = Setting
else
Supported := false;
end;

procedure TPrinterSettings.SetField(aField : integer);
begin
DevMode^.dmFields := DevMode^.dmFields or aField;
end;

procedure TPrinterSettings.ApplySettings;
begin
FPrinter.GetPrinter(FDevice, FDriver, FPort, DeviceMode);
DevMode := GlobalLock(DeviceMode);
if PaperSize = Custom then
begin
SetField(dm_paperlength);
DevMode^.dmPaperLength := PaperLength;
SetField(dm_paperwidth);
DevMode^.dmPaperWidth := PaperWidth;
{$ifdef FANG}
if Supported(dm_formname) then
begin
SetField(dm_formname);
StrPCopy(DevMode^.dmFormName, PaperFormName);
end;
//fang 900327 end
{$endif}
end;

if FDuplex then
begin
SetField(dm_duplex);
DevMode^.dmDuplex := dmdup_horizontal;
end;

if Supported(dm_PaperSize) and (PaperSize <> Default) then
begin
SetField(dm_papersize);
{$ifdef FANG}
if GetVersion() < $80000000 then
begin
if GetPrnPaperSize(FDevice, PaperFormName, iPaperSize) then
DevMode^.dmPaperSize := iPaperSize
else
DevMode^.dmPaperSize := cQRPaperTranslate[PaperSize];
end
else
{$endif}
DevMode^.dmPaperSize := cQRPaperTranslate[PaperSize];
end;

SetField(dm_copies);
DevMode^.dmCopies := FCopies;
SetField(dm_defaultsource);
DevMode^.dmDefaultSource := (DevMode^.dmDefaultSource and 256) or cQRBinTranslate[OutputBin];
SetField(dm_orientation);
if Orientation=poPortrait then
DevMode^.dmOrientation := dmorient_portrait
else
DevMode^.dmOrientation := dmorient_landscape;
FPrinter.SetPrinter(FDevice, FDriver, FPort, DeviceMode);
GlobalUnlock(DeviceMode);
end;
 
查看<<Delphi 5 开发人员指南>> 第10章
 
接受答案了.
 
后退
顶部