From: Nick Schultz on
thanks that worked!

How do I know when a box has been checked?

I tried using TVN_ITEMCHANGED, but that handler doesn't get called when I
check the checkbox.

I suppose I could check the states of all DSP checkboxes after a NM_CLICK
message, but thats pretty troublesome and won't handle the case if the user
uses a keyboard to select the checkbox

Nick

"Volker Enderlein" <volker(a)ifm.tu-chemnitz.de> wrote in message
news:eeWEUB59IHA.5316(a)TK2MSFTNGP02.phx.gbl...
> Nick Schultz schrieb:
>> I have a tree structure with multiple DSPs as parent nodes and their
>> reporting errors as the child node
>>
>> for example:
>>
>> |-DSP1
>> | |-error1
>> | |-error2
>> |
>> |-DSP2
>> |-error1
>> |-error2
>>
>> I want to be able to have checkmarks to select DSPs only. However, if I
>> enable checkboxes, all items get a checkbox.
>>
>> is there a way to just have the DSP items to have checkboxes?
>>
>> Nick
> I did have exactly the same problem yesterday and this is what I came up
> with from the MSDN documentation:
>
> To set the checkbox state:
>
> TVITEM tvi = {0};
> tvi.mask = TVIF_HANDLE | TVIF_STATE;
> tvi.hItem = hParentItem;
> tvi.stateMask = TVIS_STATEIMAGEMASK;
> tvi.state = INDEXTOSTATEIMAGEMASK(index);
> m_wndTree.SetItem(&tvi);
>
> where and index of 0 means not to show a check box, 1 means unchecked, 2
> means checked.
>
> To get the check box state:
>
> TVITEM tvi = {0};
>
> // Prepare to receive the desired information.
> tvi.mask = TVIF_HANDLE | TVIF_STATE;
> tvi.hItem = hItem;
> tvi.stateMask = TVIS_STATEIMAGEMASK;
>
> // Request the information.
> m_wndTree.GetItem(&tvi);
>
> // Return zero if it's not checked, or nonzero otherwise.
> return ((BOOL)(tvi.state >> 12) -1);
>
> BTW you have to construct the TreeCtrl with the TVS_CHECKBOXES style.
>
> Hope that helps, Cheers Volker
>
> --
> Volker Enderlein
> Tel: +49 (0)371 53119651 Institut f�r Mechatronik
> Fax: +49 (0)371 53119699 Reichenhainer Strasse 88
> email: volker(a)ifm.tu-chemnitz.de D-09126 Chemnitz


From: Victor on
KB261289: http://support.microsoft.com/kb/261289

Victor

"Nick Schultz" <nick.schultz(a)flir.com> wrote in message
news:%23UWIg399IHA.3612(a)TK2MSFTNGP04.phx.gbl...
> thanks that worked!
>
> How do I know when a box has been checked?
>
> I tried using TVN_ITEMCHANGED, but that handler doesn't get called when I
> check the checkbox.
>
> I suppose I could check the states of all DSP checkboxes after a NM_CLICK
> message, but thats pretty troublesome and won't handle the case if the
> user uses a keyboard to select the checkbox
>
> Nick
>
> "Volker Enderlein" <volker(a)ifm.tu-chemnitz.de> wrote in message
> news:eeWEUB59IHA.5316(a)TK2MSFTNGP02.phx.gbl...
>> Nick Schultz schrieb:
>>> I have a tree structure with multiple DSPs as parent nodes and their
>>> reporting errors as the child node
>>>
>>> for example:
>>>
>>> |-DSP1
>>> | |-error1
>>> | |-error2
>>> |
>>> |-DSP2
>>> |-error1
>>> |-error2
>>>
>>> I want to be able to have checkmarks to select DSPs only. However, if I
>>> enable checkboxes, all items get a checkbox.
>>>
>>> is there a way to just have the DSP items to have checkboxes?
>>>
>>> Nick
>> I did have exactly the same problem yesterday and this is what I came up
>> with from the MSDN documentation:
>>
>> To set the checkbox state:
>>
>> TVITEM tvi = {0};
>> tvi.mask = TVIF_HANDLE | TVIF_STATE;
>> tvi.hItem = hParentItem;
>> tvi.stateMask = TVIS_STATEIMAGEMASK;
>> tvi.state = INDEXTOSTATEIMAGEMASK(index);
>> m_wndTree.SetItem(&tvi);
>>
>> where and index of 0 means not to show a check box, 1 means unchecked, 2
>> means checked.
>>
>> To get the check box state:
>>
>> TVITEM tvi = {0};
>>
>> // Prepare to receive the desired information.
>> tvi.mask = TVIF_HANDLE | TVIF_STATE;
>> tvi.hItem = hItem;
>> tvi.stateMask = TVIS_STATEIMAGEMASK;
>>
>> // Request the information.
>> m_wndTree.GetItem(&tvi);
>>
>> // Return zero if it's not checked, or nonzero otherwise.
>> return ((BOOL)(tvi.state >> 12) -1);
>>
>> BTW you have to construct the TreeCtrl with the TVS_CHECKBOXES style.
>>
>> Hope that helps, Cheers Volker
>>
>> --
>> Volker Enderlein
>> Tel: +49 (0)371 53119651 Institut f�r Mechatronik
>> Fax: +49 (0)371 53119699 Reichenhainer Strasse 88
>> email: volker(a)ifm.tu-chemnitz.de D-09126 Chemnitz
>
>


From: Volker Enderlein on
Nick Schultz schrieb:
> thanks that worked!
>
> How do I know when a box has been checked?
>
> I tried using TVN_ITEMCHANGED, but that handler doesn't get called when I
> check the checkbox.
>
> I suppose I could check the states of all DSP checkboxes after a NM_CLICK
> message, but thats pretty troublesome and won't handle the case if the user
> uses a keyboard to select the checkbox
>
> Nick
>
> "Volker Enderlein" <volker(a)ifm.tu-chemnitz.de> wrote in message
> news:eeWEUB59IHA.5316(a)TK2MSFTNGP02.phx.gbl...
>> Nick Schultz schrieb:
>>> I have a tree structure with multiple DSPs as parent nodes and their
>>> reporting errors as the child node
>>>
>>> for example:
>>>
>>> |-DSP1
>>> | |-error1
>>> | |-error2
>>> |
>>> |-DSP2
>>> |-error1
>>> |-error2
>>>
>>> I want to be able to have checkmarks to select DSPs only. However, if I
>>> enable checkboxes, all items get a checkbox.
>>>
>>> is there a way to just have the DSP items to have checkboxes?
>>>
>>> Nick
>> I did have exactly the same problem yesterday and this is what I came up
>> with from the MSDN documentation:
>>
>> To set the checkbox state:
>>
>> TVITEM tvi = {0};
>> tvi.mask = TVIF_HANDLE | TVIF_STATE;
>> tvi.hItem = hParentItem;
>> tvi.stateMask = TVIS_STATEIMAGEMASK;
>> tvi.state = INDEXTOSTATEIMAGEMASK(index);
>> m_wndTree.SetItem(&tvi);
>>
>> where and index of 0 means not to show a check box, 1 means unchecked, 2
>> means checked.
>>
>> To get the check box state:
>>
>> TVITEM tvi = {0};
>>
>> // Prepare to receive the desired information.
>> tvi.mask = TVIF_HANDLE | TVIF_STATE;
>> tvi.hItem = hItem;
>> tvi.stateMask = TVIS_STATEIMAGEMASK;
>>
>> // Request the information.
>> m_wndTree.GetItem(&tvi);
>>
>> // Return zero if it's not checked, or nonzero otherwise.
>> return ((BOOL)(tvi.state >> 12) -1);
>>
>> BTW you have to construct the TreeCtrl with the TVS_CHECKBOXES style.
>>
>> Hope that helps, Cheers Volker

Hi Nick,

a word of warning after rereading the doc. If you create your TreeCtrl
with the TVS_CHECKBOXES style you may facing a wrong appearance the
first time you call your program.

The docs clearly say not to use this style when creating the TreeCtrl
but to add it later with a SetWindowLong call.

// Create tree windows.
const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES |
TVS_LINESATROOT | TVS_HASBUTTONS;

if (!m_wndTree.Create (dwViewStyle, rectDummy, this, IDC_TREECTRL))
{
TRACE0("Failed to create tree ctrl\n");
return -1; // fail to create
}

SetWindowLong(m_wndTree, GWL_STYLE, dwViewStyle | TVS_CHECKBOXES);

Hope that helps, Cheers Volker

--
Volker Enderlein
Tel: +49 (0)371 53119651 Institut f�r Mechatronik
Fax: +49 (0)371 53119699 Reichenhainer Strasse 88
email: volker(a)ifm.tu-chemnitz.de D-09126 Chemnitz
From: Victor on
Well, MFC CWnd::ModifyStyle method will also work pretty good:

if (!m_wndTree.Create (dwViewStyle, rectDummy, this, IDC_TREECTRL))
{
TRACE0("Failed to create tree ctrl\n");
return -1; // fail to create
}
m_wndTree.ModifyStyle(0, TVS_CHECKBOXES);

Victor

"Volker Enderlein" wrote:

> Nick Schultz schrieb:
> > thanks that worked!
> >
> > How do I know when a box has been checked?
> >
> > I tried using TVN_ITEMCHANGED, but that handler doesn't get called when I
> > check the checkbox.
> >
> > I suppose I could check the states of all DSP checkboxes after a NM_CLICK
> > message, but thats pretty troublesome and won't handle the case if the user
> > uses a keyboard to select the checkbox
> >
> > Nick
> >
> > "Volker Enderlein" <volker(a)ifm.tu-chemnitz.de> wrote in message
> > news:eeWEUB59IHA.5316(a)TK2MSFTNGP02.phx.gbl...
> >> Nick Schultz schrieb:
> >>> I have a tree structure with multiple DSPs as parent nodes and their
> >>> reporting errors as the child node
> >>>
> >>> for example:
> >>>
> >>> |-DSP1
> >>> | |-error1
> >>> | |-error2
> >>> |
> >>> |-DSP2
> >>> |-error1
> >>> |-error2
> >>>
> >>> I want to be able to have checkmarks to select DSPs only. However, if I
> >>> enable checkboxes, all items get a checkbox.
> >>>
> >>> is there a way to just have the DSP items to have checkboxes?
> >>>
> >>> Nick
> >> I did have exactly the same problem yesterday and this is what I came up
> >> with from the MSDN documentation:
> >>
> >> To set the checkbox state:
> >>
> >> TVITEM tvi = {0};
> >> tvi.mask = TVIF_HANDLE | TVIF_STATE;
> >> tvi.hItem = hParentItem;
> >> tvi.stateMask = TVIS_STATEIMAGEMASK;
> >> tvi.state = INDEXTOSTATEIMAGEMASK(index);
> >> m_wndTree.SetItem(&tvi);
> >>
> >> where and index of 0 means not to show a check box, 1 means unchecked, 2
> >> means checked.
> >>
> >> To get the check box state:
> >>
> >> TVITEM tvi = {0};
> >>
> >> // Prepare to receive the desired information.
> >> tvi.mask = TVIF_HANDLE | TVIF_STATE;
> >> tvi.hItem = hItem;
> >> tvi.stateMask = TVIS_STATEIMAGEMASK;
> >>
> >> // Request the information.
> >> m_wndTree.GetItem(&tvi);
> >>
> >> // Return zero if it's not checked, or nonzero otherwise.
> >> return ((BOOL)(tvi.state >> 12) -1);
> >>
> >> BTW you have to construct the TreeCtrl with the TVS_CHECKBOXES style.
> >>
> >> Hope that helps, Cheers Volker
>
> Hi Nick,
>
> a word of warning after rereading the doc. If you create your TreeCtrl
> with the TVS_CHECKBOXES style you may facing a wrong appearance the
> first time you call your program.
>
> The docs clearly say not to use this style when creating the TreeCtrl
> but to add it later with a SetWindowLong call.
>
> // Create tree windows.
> const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | TVS_HASLINES |
> TVS_LINESATROOT | TVS_HASBUTTONS;
>
> if (!m_wndTree.Create (dwViewStyle, rectDummy, this, IDC_TREECTRL))
> {
> TRACE0("Failed to create tree ctrl\n");
> return -1; // fail to create
> }
>
> SetWindowLong(m_wndTree, GWL_STYLE, dwViewStyle | TVS_CHECKBOXES);
>
> Hope that helps, Cheers Volker
>
> --
> Volker Enderlein
> Tel: +49 (0)371 53119651 Institut für Mechatronik
> Fax: +49 (0)371 53119699 Reichenhainer Strasse 88
> email: volker(a)ifm.tu-chemnitz.de D-09126 Chemnitz
>