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

Fun with CTreeCtrl

76 views
Skip to first unread message

Richard Kalton

unread,
Apr 17, 1997, 3:00:00 AM4/17/97
to

I have a CTreeCtrl object with 3 roots defined. I want to be able to
display one of three modeless dialog boxes as a result of selecting
any of the roots (or their children). I have encountered a number of
problems:

1. At present I am using a CFileTree object (derived from CTreeCtrl)
within the view so as to allow me to “intercept” the TVN_SELCHANGED
messages. I would like to derive the view from CTreeView so as to get
the benefits of automatic re-sizing etc. If I were to derive the view
from CTreeView where can I get hold of the TVN_SELCHANGED message?

2. On starting the application if I select anywhere within the view,
the first tree root item appears highlighted and a TVN_SELCHANGED
message is sent to the CFileTree object specifying the first tree
root. Checking the status of itemNew within the NMHDR at this point
indicates the first item has been selected but that no item has focus.
Can this be suppressed? Can I make it so that TVN_SELCHANGED messages
are only sent when tree items are selected (without doing my own hit
testing)?

3. I don’t seem to be able to get focus to the modeless dialog
windows. It seems as though the view won’t release focus because a
tree item is selected.

I’ve tried using SelectItem(NULL) but this results in an additional
TVN_SELCHANGED message for the first tree root item aswell as for the
null selection.

I’ve also tried using SetItemState to make the item un-selected after
I’ve identified the appropriate response. This appeared to have no
effect whatsoever.

Any good ideas to solve any of these problems would be very gratefully
received.

Thanks,


Rachel R.

unread,
Apr 17, 1997, 3:00:00 AM4/17/97
to

rdka...@taz.dra.hmg.gb (Richard Kalton) wrote:
>messages. I would like to derive the view from CTreeView so as to get
>the benefits of automatic re-sizing etc. If I were to derive the view
>from CTreeView where can I get hold of the TVN_SELCHANGED message?

You can reflect the control's message using ON_NOTIFY_REFLECT. For
example,

BEGIN_MESSAGE_MAP(CSomeTreeView, CTreeView)
//{{AFX_MSG_MAP(CSomeTreeView)
ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelChanged)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Rachel R.

Patrick Sweeney

unread,
Apr 17, 1997, 3:00:00 AM4/17/97
to rdka...@taz.dra.hmg.gb

Richard Kalton wrote:
>
> I have a CTreeCtrl object with 3 roots defined. I want to be able to
> display one of three modeless dialog boxes as a result of selecting
> any of the roots (or their children). I have encountered a number of
> problems:
>
> 1. At present I am using a CFileTree object (derived from CTreeCtrl)
> within the view so as to allow me to “intercept” the TVN_SELCHANGED
> messages. I would like to derive the view from CTreeView so as to get
> the benefits of automatic re-sizing etc. If I were to derive the view
> from CTreeView where can I get hold of the TVN_SELCHANGED message?

I also had a similiar problem in intecepting TVN_SELCHANGED. The key is
to define your message map using ON_NOTIFY_REFLECT(TVN_SELCHANGED, ...)
Here is how I do it:
First declare your class as:
class CSceneGraphTree : public CTreeView
{
protected:
DECLARE_DYNCREATE(CSceneGraphTree)
protected:
// Generated message map functions
//{{AFX_MSG(CSceneGraphTree)
afx_msg void OnSelchangedScenegraphTree(NMHDR* pNMHDR, LRESULT*
pResult);
}
Then implement it as:
IMPLEMENT_DYNCREATE(CSceneGraphTree, CTreeView)
BEGIN_MESSAGE_MAP(CSceneGraphTree, CTreeView)
//{{AFX_MSG_MAP(CSceneGraphTree)
ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchangedScenegraphTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void
CSceneGraphTree::OnSelchangedScenegraphTree(NMHDR* pNMHDR, LRESULT*
pResult)
{
...do something...
}


>
> 2. On starting the application if I select anywhere within the view,
> the first tree root item appears highlighted and a TVN_SELCHANGED
> message is sent to the CFileTree object specifying the first tree
> root. Checking the status of itemNew within the NMHDR at this point
> indicates the first item has been selected but that no item has focus.
> Can this be suppressed? Can I make it so that TVN_SELCHANGED messages
> are only sent when tree items are selected (without doing my own hit
> testing)?

Not sure.

>
> 3. I don’t seem to be able to get focus to the modeless dialog
> windows. It seems as though the view won’t release focus because a
> tree item is selected.
>
> I’ve tried using SelectItem(NULL) but this results in an additional
> TVN_SELCHANGED message for the first tree root item aswell as for the
> null selection.
>
> I’ve also tried using SetItemState to make the item un-selected after
> I’ve identified the appropriate response. This appeared to have no
> effect whatsoever.
>
> Any good ideas to solve any of these problems would be very gratefully
> received.
>
> Thanks,

- pat
p...@clark.net
http://www.clark.net/pub/pjs

0 new messages