Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get a notification from aTreeView having the TVIS_CHECKBOXES style

420 views
Skip to first unread message

Torsten Müller

unread,
Feb 8, 1999, 3:00:00 AM2/8/99
to
I have a TreeView with checkboxes on each item. Now I want to react
immediately on checking or un-checking an item.

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.


David Lowndes

unread,
Feb 8, 1999, 3:00:00 AM2/8/99
to

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.

a...@halcyon.com

unread,
Feb 8, 1999, 3:00:00 AM2/8/99
to
The MFC source is always a good place to look for this kind
of thing. Here's how they do it in version shipped w/ VC 6.0:

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)


David Lowndes

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
>The MFC source is always a good place to look for this kind
>of thing. Here's how they do it in version shipped w/ VC 6.0:

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?

0 new messages