Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize tree control to fit contents

Status
Not open for further replies.

Vachaun22

Programmer
Oct 7, 2003
171
US
I'm using a framework that themes controls to look like office 2007, XP, etc. This particular framework has a resizeable dialog window in which you can anchor controls so they are automatically sized when the dialg is sized, and will add scrollbars when necessary.

I'm using a CTreeCtrl on this particular dialog, so I need to make the CTreeCtrl non-scrollable, and resize it to fit the contents (along with it's parent dialog) so the framework will draw the scroll bars instead of the CTreeCtrl.

Is there a way to resize the CTreeCtrl to fit it's contents? I would assume it boils down to calculating how much space the items to be displayed would take up, then send the CTreeCtrl and dialog a WM_SIZE message. But I'm not sure how I'd calculate the amount of space required by the items to be displayed.

Any help would be appreciated. Thanks.
 
1) Are your nodes multi-line or single line
2) How deeply do you nest?
3) Are all nodes always expanded or can they be contracted as well.

If it is only single line, then the easiest way is to recurse down the tree and count the number of items in each node. When you have the total number of items and nodes, multiply them by the size of a single line. If it is multi line, you have to add as you go along.

 
In this instance they are only single line, and how deep the nodes go will depend on the database. And nodes can be collapsed.

What I had thought would be to use the CTreeCtrl::GetVisibleItems() function, then multiply that by the height returned by MeasureItem();. My problem with that is it really doesn't specify if GetVisibleItems() would return the number of actual visible items (based on the window size) or if it's the number of items visible assuming the window is large enough to show the entire contents.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top