to print the TTreeView and TListView

                            Standard TTreeView and TListView allow to print the contents to any
canvas (bitmap or printer etc). All what you need is to send the
WM_PRINT message.

The code below demonstrate how you may print to bitmap file:

- to print listview
var
 bmp: TBitmap;
begin
 bmp := TBitmap.Create;
 try
   bmp.Width := ListView1.Width;
   bmp.Height := ListView1.Height;
   bmp.Canvas.Lock;
   try
     ListView1.Perform(WM_PRINT, bmp.Canvas.Handle, PRF_CHILDREN or
PRF_CLIENT or PRF_NONCLIENT);
   finally
     bmp.Canvas.UnLock;
     bmp.SaveToFile('d: ree.bmp')
   end;
 finally
   bmp.Free
 end;
end;


- to print treeview
var
 bmp: TBitmap;
begin
 bmp := TBitmap.Create;
 try
   bmp.Width := TreeView1.Width;
   bmp.Height := TreeView1.Height;
   bmp.Canvas.Lock;
   try
     TreeView1.Perform(WM_PRINT, bmp.Canvas.Handle, PRF_CHILDREN or
PRF_CLIENT or PRF_NONCLIENT);
   finally
     bmp.Canvas.UnLock;
     bmp.SaveToFile('d: ree.bmp')
   end;
 finally
   bmp.Free
 end;
end;

As you see all what you need is to create a bitmap with desired sizes
and send the WM_PRINT message with handle of canvas as parameter.

But note that only visible part of control will be printed and control
will print the current state as is. For example, if some nodes are
collapsed, you'll receive same "snapshot" on canvas.
 
Author: Mike Shkolnik   WebPage: http://www.scalabium.com
 

                                

查看回复