×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Resize tree control to fit contents

Resize tree control to fit contents

Resize tree control to fit contents

(OP)
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.

RE: Resize tree control to fit contents

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.

RE: Resize tree control to fit contents

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close