Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

c++ - Is it possible to remove some checkboxes from tree view's nodes?

I have made a tree view control in dialog box, using resource editor.

I have set the checkbox style with SetWindowLongPtr( ... ) function, the way Microsoft described.

Every node has checkbox this way, yet I need only some to have checkbox, and some to have nothing standing next to their text ( parent nodes do NOT have checkbox, only child or simple ones->ones without children ).

Can this be achieved by subclassing, or maybe with custom/owner draw or perhaps superclassing ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The tree control uses state images to draw the checkboxes. According to the docs on the TVS_CHECKBOXES style:

State image 1 is the unchecked box and state image 2 is the checked box. Setting the state image to zero removes the check box altogether.

So something like this should let you remove the check box from a tree item:

TVITEM tvi;
tvi.hItem = hTreeItem;
tvi.mask = TVIF_STATE;
tvi.stateMask = TVIS_STATEIMAGEMASK;
tvi.state = 0;
TreeView_SetItem(hWndTree, &tvi);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...