This has really help me, thank you! I did a quick conversion to get this to print a list view and it worked first time. One problem is that the list header (report mode) doesn't print properly - any idea's on a fix?
A couple of people have commented on the problem with printing large trees - Windows fails to create such a large bitmap.
For your info, I've tried using a bitmap the size of one (paper) page - it works really well. All you have to do is at the start of OnPrint(), set the window origin (SetWindowOrg) of the memory DC (MemDC) to the coordinates of the top hItem that is going to be drawn. Then send the WM_PAINT message and StretchDIBits as before.
UPDATE: Actually there's still a problem with very large trees. The MoveWindow call fails - Windows won't allow you to make the window any larger (I've even tried playing with OnGetMinMaxInfo(), but to no avail). Note that _this_ is the cause of some peoples black scroll bar problem - they won't go away because the window isn't as large as the tree.
Problem: It seems that with this code if you print a tree that is longer than one page in length, you'll see
a think black vertical line where normally the vertical scrollbar would draw on right side of the view.
Anyone have the solution to removing this thick black line?
My guess is, the solution lies in the following area: When the view is painted the code turns scrollbars
off, which is good. However, when the monochrome mask is made, I think it's made with a width size that would
allow for a vertical scrollbar on the right side. Thus, when the bitmaps are copied together they have this
thick black line on the right side. Do you think this is what the problem is? How does one make the mask
smaller to not include space for a vertical scrollbar?
This works really well and proves to be really useful but there is one problem.
If the tree contains a lot of items which it does in my case (take for example when the tree is fully
expanded it corresponds to approximately 50 pages if it were to be printed) I get an ASSERT failure on the
Finally a job well done...I've been looking for some 'drop in' code to print the contents of a TreeView ever
since MS introduced it! Hope you have plans for coding the printing of a ListView control in the works!