Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips


#163: How can print the TTreeView and/or 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:\tree.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:\tree.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.


Published: April 21, 2004

See also
 
Viewer for MS Outlook Messages
Metafile Convert
Excel Web-stream
Protected Storage Viewer
Paradox to Text converter
Clarion to Text converter
Word Web-stream
SMMsg suite
ABA Database Convert
SMExport suite
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising