如何在运行时知道各类纸张的尺寸,如A4,A3的Width和Height(100分求解)(100分)

  • 主题发起人 主题发起人 fl95149
  • 开始时间 开始时间
F

fl95149

Unregistered / Unconfirmed
GUEST, unregistred user!
想实现类似WORD的纸张设置功能
 
大虾们帮忙啊
 
你用QUICKREPORT不就行了?你用PrinterDialog也可以进行设置呀.
我这儿有一段设置纸张大小的代码,是从别人那儿抄来的.忘了是谁的了.如下:
unit uPrintPaperSetup;
interface
uses windows,printers,SysUtils;
procedure SetPaperSize(X, Y: Integer);
function TransformX(X: Integer): Integer;
function TransformY(Y: Integer): Integer;
function InitPrinter: Boolean;
implementation
var
RateX, RateY: Integer;

function InitPrinter: Boolean;
begin
Result := Printer.Printers.Count > 0;
RateX := MulDiv(GetDeviceCaps(Printer.Handle, LOGPIXELSX), 1000, 254);
RateY := MulDiv(GetDeviceCaps(Printer.Handle, LOGPIXELSY), 1000, 254);
end;

procedure SetPaperSize(X, Y: Integer);
var
Device, Driver, Port: PChar;
HDMode: THandle;
PDMode: PDevMode;
begin
Device := StrAlloc(cchDeviceName);
Driver := StrAlloc(MAX_PATH);
Port := StrAlloc(32);
try
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, HDMode);
if HDMode <> 0 then
begin
PDMode := GlobalLock(HDMode);
if PDMode <> nil then
begin
with PDMode^do
begin
dmPaperSize := 256;
dmPaperWidth := X;
dmPaperLength := Y;
dmFields := dmFields or DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
GlobalUnlock(HDMode);
end;
Printer.PrinterIndex := Printer.PrinterIndex;
end;
end;
finally
StrDispose(Device);
StrDispose(Driver);
StrDispose(Port);
end;
end;

function TransformX(X: Integer): Integer;
begin
Result := MulDiv(X, RateX, 1000);
end;

function TransformY(Y: Integer): Integer;
begin
Result := MulDiv(Y, RateY, 1000);
end;

procedure TransformPoint(Point: TPoint);
begin
Point.x := TransformX(Point.x);
Point.y := TransformY(Point.y);
end;

procedure TransformRect(Rect: TRect);
begin
Rect.Left := TransformX(Rect.Left);
Rect.Right := TransformX(Rect.Right);
Rect.Top := TransformY(Rect.Top);
Rect.Bottom := TransformY(Rect.Bottom);
end;

end.

调用:
uses uPrintPaperSetup;
if not InitPrinter then
Application.MessageBox('', '', mb_IconError + mb_OK)
else
SetPaperSize(800, 800);//设定纸张为8厘米,这儿的精度是0.1mm.
 
你是不是想随时取得当前打印纸的宽度、高度(以毫米为单位),
我这儿有现成的,给我发email:zbl3559@sina.com,我给你恢复。
 
我这儿有现成的,把你的email地址email to :yaoguotian@sina.com
我给你一个现成的窗体。
 
能给我一份吗?万分感谢!
zhang_yz@163.com
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部