I have a problem in printing TreeView.
I am using Delphi-5. I am also using images
in TreeVie to describe each node.
I tried to print treeview in the following way...
procedure TfrmCommArchConfg.BitBtn1Click(Sender: TObject);
begin
With Printer Do
Begin
BeginDoc;
tvPhysicalView.PaintTo(Handle, 100, 100);
EndDoc;
End;
end;
But I observed print out comes as a very small image which is not readable.
So how to get across this. IS there any better approach to print treeview or Can I do something more to PaintTo method. How do I specify the size of print out.
Thanks for your suggestions...
Praveen A. Karki.
You need to use SetWindowExtEx/SetViewPortExtEx pair to adjust zooming.
Please try to search for SetWindowExtEx or SetViewPortExtEx on
www.delphi3000.com. There's my article there about how to manage such
things.
--
Eugene Mayevski,
EldoS Group, chief coordinator
Custom software development for Windows, Palm and WinCE
http://www.eldos.org/outsourcing.html
Printers have a very different resolution (basically the size of a pixel)
from the screen. So you need to scale the output. This can be done using
mapping modes. Or you can first paint the treeview to a bitmap and
then use StretchDIBits to print that scaled.
Print a treeview
var
bmp: TBitmap;
begin
bmp:= TBitmap.Create;
try
bmp.width := treeview.width;
bmp.height := treeview.height;
bmp.canvas.lock;
try
treeview.perform( WM_PRINT,
bmp.canvas.handle,
PRF_CHILDREN or PRF_CLIENT or
PRF_NONCLIENT );
finally
bmp.canvas.unlock;
end;
...print the bitmap as device-independent bitmap using
StretchDIBits
finally
bmp.free
end;
Drawing directly to the printer canvas is probably possible but you have
to mess with mapping modes, scale the printer canvas, move its origin
and so on, the above may be easier to code, especially if you already
have a PrintBitmap routine flying around somewhere.
Lets see, i should have some bits and pieces around that demonstrate how
this scaling via mapping modes work...
Procedure PaintControl( aControl: TWinControl; aCanvas: TCanvas;
offsetx, offsety: Integer );
Begin
SaveDC( aCanvas.handle );
try
SetWindowOrgEx( aCanvas.handle,
-(acontrol.left + offsetx),
-(acontrol.top + offsety),
nil );
acontrol.perform( wm_print,
acanvas.handle,
PRF_CHILDREN or PRF_CLIENT or PRF_NONCLIENT or
PRF_ERASEBKGND );
finally
RestoreDC( aCanvas.handle, -1 );
end;
End;
printer.begindoc;
try
{ Scale printer to screen resolution. }
SetMapMode( printer.canvas.handle, MM_ANISOTROPIC );
SetWindowExtEx(printer.canvas.handle,
GetDeviceCaps(canvas.handle, LOGPIXELSX),
GetDeviceCaps(canvas.handle, LOGPIXELSY),
Nil);
SetViewportExtEx(printer.canvas.handle,
GetDeviceCaps(printer.canvas.handle, LOGPIXELSX),
GetDeviceCaps(printer.canvas.handle, LOGPIXELSY),
Nil);
PaintControl( treeview1, 100, 100 );
finally
printer.enddoc
end;
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.