A Print Enabled Tree Control


Full Text Search: The Key to Better Natural Language Queries for NoSQL in Node.js

I realized a lot of developers are interested in code for printing CTreectrl. I was in the same situation and tried a lot of different ways, but every approach had its disadvantage.

The simplest solution seemed in the call of CWnd::Print(...), but this only prints the visible part of the control, which was not what I wanted. One way to make this approach work was to scroll the TreeCtrl in the printing code from the start to the end of the control, calling CWnd::Print(...) after every scroll, which was a little bit weird for me. Additionally I wanted as much flexibility in my code as possible, which means printing with or without icons, lines, buttons.

That's why I began to implement the whole stuff by myself, following the next few steps:

Init ImageList:

In my opinion and my understanding of OOD the Treecontrol should be able to display itself, that's why it should have the imagelist and initialize it.


This is also done by hand, like everything else. Iterate through the tree and create an array with the PagingInfos:

struct PagingInfos
   HTREEITEM    m_hStartItem;
   int          m_iNumberOfItems;


Iterate through the tree and print every node by code, including lines and buttons.

Imagelist vs DIB:

In an additional step I wanted to print the tree in color. This was easy for text, but not for the icons. I tried a lot to convert the imagelist to DIB, but what I really needed was a method, which gives back the DIB of one icon, not of the whole Imagelist.

Bugs and Improvements:

  • Compiling the release version is now working too.
  • If the convertion to DIB failes the program gives back an errorcode and prints without graphic( see Comment below).


After the first release, I received some emails about problems with the example project, which was crashing under some conditions. My problem is, that every time I tested my code under the described conditions it worked fine. What I've done now, was to extend the project with more errorhandling and it would be nice, if all users which are receiving errorcodes, could report me the following informations:

  • Errorcode
  • OS with servicepack
  • IDE with servicepack
  • Optional: Which conversion failed

Please report all bugs and improvements to me, thanks and enjoy it.



  • Broken Link

    Posted by anand_study on 08/30/2007 02:24am

    Unable to download samplecode ?

  • Fine.

    Posted by Legacy on 01/16/2004 12:00am

    Originally posted by: Feroz Zahid.

    Good work with the printing but let it be done without using microsoft foundation classes.

  • Bugs and Updates

    Posted by Legacy on 07/10/2002 12:00am

    Originally posted by: Mike Wild

    Sorry Guys
    but I gave up to update this article, because I tried it a few times, but it didn't realy work.
    I know about the Bugs you reported and I really wanted to post a new version, but it was so annoying.
    At the moment I'm trying to do the printing for C# and perhaps you see my posting there again.


    Posted by Legacy on 05/30/2002 12:00am

    Originally posted by: Niranjan

    My requirement is to print all the elements weather expanded or not expanded......Your code provides printing for items which are expanded only do you have any idea how i can implement it for printing for items under the nodes which are not expanded also?? I want to print the items under all nodes (including the nodes) even if the node is not expanded... hope to hear from u soon...
    Thanks a lot

  • Need help for using CWnd::Print

    Posted by Legacy on 11/26/2001 12:00am

    Originally posted by: emily

    I try to use CWnd::Print(...) tp print the entire dialog
    box, but it didn't work at all.
    Anyone used this function call before?


  • ww

    Posted by Legacy on 08/09/2001 12:00am

    Originally posted by: nazia

    what will be steps and code of tree control

  • array not initialized

    Posted by Legacy on 06/13/2001 12:00am

    Originally posted by: chuck

    in the constructor


    // added the line
    m_dibButtons[0] = NULL; m_dibButtons[1] = NULL;

    This eliminated an error in CAdvancedTreeCtrl::DeleteDibArrays when doing a print preview.

    this was with vc6, sp5

  • How about printing with check boxes??

    Posted by Legacy on 01/19/2000 12:00am

    Originally posted by: Steve Chia

    If a tree control has the check box property set, it will appear in the GUI but not in the printout. Does anyone know how to add in the check box in the printout??

    Thank you very much!! : )

  • How about printing with check boxes??

    Posted by Legacy on 01/19/2000 12:00am

    Originally posted by: Steve Chia

    If a tree control has the check box property set, it will appear in the GUI but not in the printout. Does anyone know how to add in the check box in the printout??

    Thank you very much!! : )

  • You are correct

    Posted by Legacy on 04/29/1999 12:00am

    Originally posted by: Douglas Peterson

    I can see now that you are correct. The documentation is inacurate.

    However, if two items are equal, does it matter if their positions are swapped?

    1 < should this go before or after the other 1?

    The result is that the items are correctly sorted.

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Using Internet of Things (IoT) technologies, colleges and universities are linking anything and everything to create new applications that elevate the campus experience. It's called a Smart Campus. And it's transforming campus life for students, faculty and visitors. When everything is connected, devices and applications can interact with users and with each other in ways that weren't possible before: digital classrooms, connected campus ID cards, connected lighting and building environmental systems and …

  • How does this impact your content strategy? Content management markets are changing rapidly. Due to increased expectations of users, changes in IT and the need for organizations to rethink their digital strategy, Gartner has launched new Magic Quadrants (MQs) for Content Services Platforms (CSP) and Content Collaboration Platforms (CCP). These MQs have updated the definition of previous Enterprise Content Management (ECM) and Enterprise File Sync and Share (EFSS) markets respectively, and are tightly connected …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date