Unlike the ListView-Control the TreeView does not send a notification like
LVN_ITEMCHANGED. Has anybody a better idea than catching WM_LBUTTONDOWN and
WM_KEYDOWN in a subclassed CTreeCtrl class ?
Please help.
Torsten,
Looking with Spy++ there is an NM_CUSTOMDRAW message generated that
corresponds with the check/uncheck redrawing. Looking at the docs I'd
hoped that the CDIS_CHECKED flag would indicate the state, but in a
simple test I've tried, it appears not to do so. There must be a way
of handling this operation - does anyone else have any clues?
Dave
----
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.
BOOL CTreeCtrl::GetCheck(HTREEITEM hItem) const
{
ASSERT(::IsWindow(m_hWnd));
TVITEM item;
item.mask = TVIF_HANDLE | TVIF_STATE;
item.hItem = hItem;
item.stateMask = TVIS_STATEIMAGEMASK;
VERIFY(::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item));
// Return zero if it's not checked, or nonzero otherwise.
return ((BOOL)(item.state >> 12) -1);
}
BOOL CTreeCtrl::SetCheck(HTREEITEM hItem, BOOL fCheck)
{
ASSERT(::IsWindow(m_hWnd));
TVITEM item;
item.mask = TVIF_HANDLE | TVIF_STATE;
item.hItem = hItem;
item.stateMask = TVIS_STATEIMAGEMASK;
/*
Since state images are one-based, 1 in this macro turns the check
off, and 2 turns it on.
*/
item.state = INDEXTOSTATEIMAGEMASK((fCheck ? 2 : 1));
return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)&item);
}
David Lowndes (dav...@mvps.org) wrote:
: >I have a TreeView with checkboxes on each item. Now I want to react
--
--
/* Andrew */
WWW: http://www.halcyon.com/ast
Email: a...@halcyon.com (remove nospam from reply address)
It is indeed, and I was aware of TVM_GETITEM from my tests, but I
couldn't get it to help in providing an elegant solution when handling
just the NM_CUSTOMDRAW message. Do you have neat solution?