How can I wrap the item text in treeview control in WTL

616 views Asked by At

I am maintaining a ATL/WTL project in which it contains a tree view. The class used for the tree view is CTreeViewCtrl. Now the client has asked to wrap the tree item text when it goes out of view though we can re-size the pane or scroll left of right anytime to see the content. It also shows the full string, when hidden, as a tool tip when mouse pointer is hovered on a tree item.

Is there any way I can set in the tree item or the tree view to wrap the text content.

Thanks

1

There are 1 answers

0
047 On

There's a way: do custom drawing of treeview's items while processing NM_CUSTOMDRAW message from treeview control, specifically the CDDS_ITEMPOSTPAINT drawing stage.

On custom drawing you draw multi-line text using ::DrawText() with DT_WORDBREAK flag. In order to have enough space available for text to fit in use TVITEMEX structure's iIntegral field. You'll have to specify number of lines for each node by sending TVM_SETITEM message to treeview window with pointer to TVITEMEX as LPARAM.

You'll have to recalculate number of lines for each of tree's nodes every time treeview's width changes (WM_SIZE).