|
|
Comments and Discussions
|
|
 |

|
hi in Tree contral
How can i set the color Accoring to the text
measn if one item like
"world Cup(2001)"
"world Cup(2002)"
"world Cup(2003)"
"world Cup(2004)"
i need (2001) in Diffrent colour so how can i do that ?
plz help
Ashutosh Soni
Software Engineer
Mumbai(India)
|
|
|
|

|
hi in Tree contral
How can i set the color Accoring to the text
measn if one item like
"world Cup(2001)"
"world Cup(2002)"
"world Cup(2003)"
"world Cup(2004)"
i need (2001) in Diffrent colour so how can i do that ?
plz help
|
|
|
|
|
|

|
How do I hide the selection of an item. I have developed an own multiselect function and would to hide the original selection (the blue color in CTreeCtrl).
_____________________________
...and justice for all
APe
|
|
|
|

|
This is a good sample and simple, but for me I have put Tree or CTreeCtrl in the Docking Control with a lot of children.
Could anyone show how to use TVN_SELCHANGED in order to display one of formviews in mainwindow when I selchange one of the node. Your help will be very appreciated.
The Novice
|
|
|
|

|
Why not expand the CSimpleTreeCtrl::TreeCtrlItem node interface, to also list children, define it's own label etc. Seen from an oo perspective only "MyTreeCtrlItem" can answer to what might be my label, and to how many children I have.
I recently started a discussion on experts-exchange (lemmesee[^]) on this question. My first suggestion for a node interface looked something like this:
class ITreeNode
{
virtual CString GetTreeLabel() { return "Default"; }
virtual void GetTreeChildren( CTreeNodeList& L ) {}
virtual int GetTreeImage() { return 0; }
virtual int GetTreeImageSelected( return GetTreeImage(); }
}
This hides away alot of CTreeCtrl specefic code, and leaves a clean interface for objects to implement, if they want to be able to get represented in a tree.
|
|
|
|

|
Oh, and why not let the tree itself hande right click context menu, and only ask the ITreeNode for strings to put in the popup menu. All the TrackPopupMenu() tricks is this way hidden to node objects. Tricks that I don't want to worry about when I "just want a context menu with a few choises"
class ITreeNode
{
//The tree would call this method on the right
//clicked node to have popup menu items listed
virtual void GetContextMenu( CStringList& L ) {}
//Then when user clicks an item, the tree calls
//this method to notify the node. This hides away
//message id's to each item seen from a nodes view.
virtual void OnContext( int nItemIndexSelected ) {}
}
|
|
|
|

|
Good question... However I think it is a little bit out of the scope of "Simple Tree Ctrl". What you're suggestion goes to write wrapper classes around the MFC objects which actually I tought at the beginning. But again, it was totally out of my mind when I wrote this control. And I did not write any other similar classes for other MFC controls.
So if you like to give a try I also recommend to check sigslot template headers which is available on internet somwhere ( I'm sure a quick search might give nice results). Checking some about QT (if not done yet) also will give really nice ideas I am sure...
"Computers emit waves that affect the brain, causing ... Superstitious beliefs ("the computer hates me") and magical thinking ("the program only works when I wear my hat backward"). "
from "How to Think Like a Computer Scientist"
|
|
|
|

|
I populate my CTreeCtrl with object names from my scene (Im making a scene graph).
But some of my scene objects have the same name. I use the following code to get the name of the child... but I may have picked a scene object that has the same name as others such as "crate.x" Is there a unique id for each entry in the list so I alway know which item I just picked? Is there another way?
HTREEITEM SelItem, ParentItem;
SelItem = m_TreeCtrl.GetSelectedItem();
ParentItem = m_TreeCtrl.GetParentItem(SelItem);
// Set path of object
CString m_Child;
m_Child = m_TreeCtrl.GetItemText(SelItem);
|
|
|
|

|
I have two problems:
1. CTreeCtrl::SetCheck(TRUE) does not work correctly or it is not such easy as should be; I've proved the solutions that appear from some other users, but they don't work. I have a CTreeCtrl in a dialog, and in the OnInitDialog function, I add items to the tree, and for some of them I call setCheck(TRUE), but when the dialog appears all items are not checked. Why? Doing
m_ButtonTree.ModifyStyle( TVS_CHECKBOXES,0 );
m_ButtonTree.ModifyStyle( 0, TVS_CHECKBOXES );
is not a solution...
2. The second problem is that I need to capture the event generated when I click the 'check box image' of the tree control. It is not a selection, and I've not found any other event message related with check boxes. Anybody knows how to do this?
|
|
|
|

|
OnInitDialog(){
m_Tree->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_HASLINES |TVS_LINESATROOT |
TVS_HASBUTTONS | TVS_CHECKBOXES, rc, this, 1);
m_Tree->ModifyStyle( TVS_CHECKBOXES, 0 );
m_Tree->ModifyStyle( 0, TVS_CHECKBOXES );
m_Tree->Init();
}
In the Init()funtion, I add items and SetCheck(hti, true);
It works!!
|
|
|
|

|
void CTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
UINT uFlags=0;
HTREEITEM hti = HitTest(point,&uFlags);
if(( uFlags & TVHT_ONITEMSTATEICON )&&(hti!= NULL))
{
// you click hti's check box
}
}
|
|
|
|

|
in reference to point 1, this is mentioned in the sdk docs if you read *extremely* carefully (no, nor did i)
"The TVS_CHECKBOXES style creates checkboxes next to each item. If you want to use the checkbox style, you must set the TVS_CHECKBOXES style (with SetWindowLong) after you create the tree-view control and before you populate the tree. Otherwise, the checkboxes might appear unchecked, depending on timing issues."
- mappy
|
|
|
|

|
THANK YOU !
Someon should have made this info better available. On the front page or something.
Took me 2 hours !
So again, thank you !
Greetings from The Netherlands
|
|
|
|

|
I do really like this widget but, am I wrong or CSimpleTreeCtrl doesn't accept images from CImageList ? I've tried to add a new CSimpleTreeCtrl::InsertItem member that call CTreeCtrl::InsertItem(LPCTSTR lpszItem, int nImage, int nSelectedImage, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST) but with no success. Any idea ? Thanks
|
|
|
|
|

|
Hi!
I was included this code in my program which has a edit control.
What I'm wanting to happen is, when I will click the node in the tree control, it will execute my dialog member function which changed the value on the edit box.
Can anybody help me.
Thanks,
Chris
|
|
|
|

|
When I define "_AFXDLL,_UNICODE" in project setting, it makes me able to show Japanese and Korean, etc. in the CListCtrl correctly. But when I want to do the tree expand using the "TVN_ITEMEXPANDING" event function, it fails. I find that when I double click the tree item, the event function will not be fired up. And I can't get the tree structure of the item when I use the "GetChildItem" in the "TVN_ITEMSELCHANGED" event function. The tree-item path in the event function is correct. Thanks for your answer.
|
|
|
|

|
I wrote my program using that Simple Tree Control.
using CTreeCtrl with check box...but check box does not working...
HTREEITEM h_Item = tItem->getHandle();
if (!m_treeCtrl.GetCheck(h_Item))
m_treeCtrl.SetCheck(h_Item, 1);
or
HTREEITEM hItem = m_treeCtrl.GetFirstVisibleItem();
m_treeCtrl.SetCheck(hItem, 1);
m_treeCtrl.Expand( hItem, TVE_EXPAND );
Expand() is working well...but SetCheck() is not working...
how can i use check box...??
|
|
|
|

|
Use this
mTree.ModifyStyle( 0, TVS_CHECKBOXES );
|
|
|
|

|
Didn't work, but use
m_Tree.ModifyStyle( TVS_CHECKBOXES, 0 );
m_Tree.ModifyStyle( 0, TVS_CHECKBOXES );
and it works!
|
|
|
|

|
Thanks you saved me time.
Tout programme dont la fiabilité dépend de l'homme n'est pas fiable
|
|
|
|

|
Anyone know why this might leak 4 GDI Objects on the ModifyStyle(0, TVS_CHECKBOXES) line and how to avoid it/fix it? Happens every time w/ VC++6 on the SetWindowLong() call in _AfxModifyStyle() in WINCORE.CPP.
|
|
|
|

|
another approach would be this...
SetWindowLong(m_treeCtrl, GWL_STYLE, m_trImages.GetStyle() | TVS_CHECKBOXES);
|
|
|
|

|
I use your control but didn't use in Dialog. I create it manually with CreateEX method. In my derived class,I create TreeCtrlItem in OnCreate() method. Somehow I close my application and found that TreeCtrlItem aren't deleted. I have to delete it in destructor to avoid memory leak. I thought that your control will destroy TreeCtrlItem automatically (It destroy them if control is in Dialog). So, what is the different between creating control manually and use control in Dialog?
|
|
|
|

|
Well, I did not try the case that you explained here. But what I know is creating a control using VS gui editor, and from code is quite different in MFC. -I don't know how exactly and why but I met similar cases for other controls-.
First of all are you sure that destructer for the tree control is called when you close the application. I'm not sure if MFC is referance counting for the controls. This might be a problem if you use pointers for the controls.
Probably base class (CTreeCtrl) deletes all items automatically at destruction, and when it happens derived class should clear its memory. If destructer is already called at your case, I might need to check the code. Can you send me a sample code where you met this problem?
"Computers emit waves that affect the brain, causing ... Superstitious beliefs ("the computer hates me") and magical thinking ("the program only works when I wear my hat backward"). "
from "How to Think Like a Computer Scientist"
|
|
|
|
|

|
Hi,
I'm using several simple tree controls in one of my projects adding and deleting different tree items at runtime. And did not get any error at the destruction.
If you can send me the case that you have, I'd like to check to see what's going on.
"Computers emit waves that affect the brain, causing ... Superstitious beliefs ("the computer hates me") and magical thinking ("the program only works when I wear my hat backward"). "
from "How to Think Like a Computer Scientist"
|
|
|
|
|

|
hi i want to get the tree item coordinates.
TreeView_GetItemRect is failing. its returning False.
using coordinates i want to send right button click message.
i want to know how to get the handle to Context Menu.
in my treecontrol already context menu has been attached to the tree item. whenever i right click, context menu pops up.
but instead of right click using mouse, i want to send WM_RBUTTONDOWN message to the treeitem.
actually i am sending all these messages from some other application by using handle to the treecontrol.i can get the handle to the treecontrol by FindWindowEx method.
if anybody knows, how can i get the coordinates of the tree item with respect to the screen, plz mail me to naveen.gangadharappa@honeywell.com.
if anybody knows, how can i invoke the context menu using sendmessage and how can i select some menu item from the context menu?, plz mail me to naveen.gangadharappa@honeywell.com.
|
|
|
|

|
the program is so easy to be used... thanks..
|
|
|
|

|
How changes the color of the node on-line?
|
|
|
|

|
You can use
CSimpleTreeCtrl::TreeCtrlItem::setBkColor()
CSimpleTreeCtrl::TreeCtrlItem::setTextColor()
at any time. But you may need to force the control to redraw.
|
|
|
|

|
What I mean to say is I want to changes the color of that lines, but not is the node's color.
|
|
|
|

|
It should not be as easy as changing the background or text color. I have no idea at the moment. You can check the data structures in OnCustomDraw() and see if there is something about that.
Also you may try to skip default drawing for items and find out when MFC draws that lines. To handle Post Draw Item case and redraw the lines with your own color might be another idea.
Ozgur.
|
|
|
|

|
I do a RedrawWindow of the entire control.
|
|
|
|

|
I just noticed that I did not call lClick() in any message handlers, 'cause I did not handle OnClick() message. I guess it's because I didn't need it before, selChanged() works well for most cases.
Anyway, when if an update will be required I'll add it, or remove it from article
please let me know if anyone needs lClick() really.
Sorry for that.
Ozgur.
|
|
|
|

|
Very good
Just one point that make me sad...
When You do MouseDown on a item, the old item selected become white and
will only get its right color when you do MouseUp...
kind of flicking, not pretty
anyway, thanks
Nicolas
|
|
|
|

|
Thanks for the comment, I did not notice that. Here is a quick solution: You can change the code in CSimpleTreeCtrl::OnCustomdraw(). change the existing switch case:
case CDDS_ITEMPREPAINT :
if ( bItem ) {
if ( GetSelectedItem() != bItem->getHandle() ) {
pLVCD->clrTextBk = bItem->m_bkColor ;
pLVCD->clrText = bItem->m_color ;
}
}
break ;
with the code below:
case CDDS_ITEMPREPAINT :
if ( bItem ) {
COLORREF bkColor = GetBkColor() ;
int rBW = GetRValue ( bkColor ) ;
int gBW = GetGValue ( bkColor ) ;
int bBW = GetBValue ( bkColor ) ;
int rBI = GetRValue ( pLVCD->clrTextBk ) ;
int gBI = GetGValue ( pLVCD->clrTextBk ) ;
int bBI = GetBValue ( pLVCD->clrTextBk ) ;
if ( rBW == rBI && gBW == gBI && bBW == bBI ) {
pLVCD->clrTextBk = bItem->m_bkColor ;
pLVCD->clrText = bItem->m_color ;
}
}
break ;
This should work. It is just to avoid drawing for higlighted items. I'm sure there should be some better solutions for that but this is just a quick answer . I did not compare COLORREF directly 'couse one of them has alpha value.
Anyway, I hope it helps.
|
|
|
|

|
This does not pertain directly to your article but I thought you would know the answer to my problem. I am trying to alter the style of the CTreeCtrl contained in a CTreeView project, but I can't seem to find a way to do it. I want to make the +/- buttons next to the items visible and make the tree lines visible, for example. Can you help me find the solution to this?
Thank You!
Thanks!
|
|
|
|

|
Let's see if I understood the problem correctly. I created a simple MFC Single Document application and change the base class for View class as CTreeView. Then add some items in it.
In order to change tree style you should handle Create() function in your CTreeView derived class and change the style of the view. Like below:
BOOL CTreeViewView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// add your style options
dwStyle |=TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT ;
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
hope it helps.
ozgur.
|
|
|
|

|
The article delivers on the promise. I feel there's no need to write an article on developing a kernel for a new OS to get a good rating. I'd give a solid 4.5, but since I'm going to end up using it: you get the 5.0.
Nitron
_________________________________________--
message sent on 100% recycled electrons.
|
|
|
|

|
Really simple and usefull. Thanks.
|
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
An article on using CTreeCtrl in a simpler way (I believe).
| Type | Article |
| Licence | |
| First Posted | 28 Oct 2002 |
| Views | 173,185 |
| Downloads | 3,406 |
| Bookmarked | 32 times |
|
|