这是因为打印机和屏幕的单位不同。
GetDriveCaps().
GetDriveCaps().
解决方案 »
- 我想在我做的程序中用一些快捷键,比如F3,(我要用的是F系列)弹出一个窗体
- 很奇怪的 问题,高手指教
- 如何判断串口已经打开?
- 关于adoquery1.beforepost出现的错误
- 新手请教:如何减小DELPHI可执行文件的大小?
- 用 table 可以组成的主细表关系,两个表以上table好不好设置,请问用QUERY是不是很方便语句怎么写,请赐教!
- 忘各位告知:ADO连接请问怎样让所有的DB组件禁用....如果禁用ADOTABLE1.????...如果是取消禁止那..
- CodeRush是做什么用的东东???
- 请教如何设置TreeView和StatusBar控件
- 急救!需要隐藏SERVER的方法
- cgi+Kylix
- 如何找回失去的文件?
怎么用,能不能给个例子看看?谢了
http://www.csdn.net/expert/topic/201/201720.shtm
object Form1: TForm1
Left = 192
Top = 168
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PrintScale = poNone
PixelsPerInch = 96
TextHeight = 13
object StringGrid1: TStringGrid
Left = 40
Top = 112
Width = 337
Height = 209
TabOrder = 0
end
object Button1: TButton
Left = 224
Top = 48
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end
//******* unit1.pas ************
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids;type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementationuses
Printers;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
tb:TBitmap;
Info: PBitmapInfo;
InfoSize: DWORD;
Image: Pointer;
ImageSize: DWORD;
Bits: HBITMAP;
DIBWidth, DIBHeight: Longint;
PrintWidth, PrintHeight: Longint;
begin
Tb := TBitmap.Create;
try
Tb.Width := StringGrid1.Width;
Tb.Height := StringGrid1.Height;
Tb.Canvas.Brush := StringGrid1.Brush;
Tb.Canvas.FillRect(Rect(0,0,Tb.Width,Tb.Height));
Tb.Canvas.Lock;
try
StringGrid1.PaintTo(Tb.Canvas.Handle, 0, 0);
finally
Tb.Canvas.Unlock;
end;
except
Tb.Free;
raise;
end; Printer.BeginDoc;
try
try
{ Paint bitmap to the printer }
with Printer do
begin
Bits := Tb.Handle;
GetDIBSizes(Bits, InfoSize, ImageSize);
Info := AllocMem(InfoSize);
try
Image := AllocMem(ImageSize);
try
GetDIB(Bits, 0, Info^, Image^);
with Info^.bmiHeader do
begin
DIBWidth := biWidth;
DIBHeight := biHeight;
end;
PrintWidth := MulDiv(DIBWidth, GetDeviceCaps(Handle,
LOGPIXELSX), PixelsPerInch);
PrintHeight := MulDiv(DIBHeight, GetDeviceCaps(Handle,
LOGPIXELSY), PixelsPerInch); StretchDIBits(Canvas.Handle, 0, 0, PrintWidth, PrintHeight, 0, 0,
DIBWidth, DIBHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY);
finally
FreeMem(Image, ImageSize);
end;
finally
FreeMem(Info, InfoSize);
end;
end;
finally
end;
finally
tb.free;
Printer.EndDoc;
end;end;end.