Date: 2010may17
OS: Windows
Language: C/C++
Keywords: grey, gray, disable
Q. How can I hide a checkbox in a TreeView ?
A. Here's a function that hides it. Until a user clicks on it.
You need to add more code to prevent it from re-appearing when the user
clicks on it.
BOOL SetCheckStateDisabled(HWND hwndTree, HTREEITEM hItem, const BOOL bChecked)
{
TVITEM tvItem;
ZeroMemory(&tvItem, sizeof(tvItem));
tvItem.mask = TVIF_HANDLE | TVIF_STATE;
tvItem.hItem = hItem;
tvItem.stateMask = TVIS_STATEIMAGEMASK;
// Image 3 in the tree-view check box image list is the
// disabled unchecked box. Image 4 is the disabled checked box.
tvItem.state = INDEXTOSTATEIMAGEMASK((bChecked ? 4 : 3));
return TreeView_SetItem(hwndTree, &tvItem);
}
MSDN says:
Version 5.80 displays a check box even if no image is associated with the item.
They are talking about that version of Comctl32.dll.
Which suggests this trick may not work.
But I have tried this in version 5.82 (Vista) and it does work there.