 |
|
 |
Hi Lion,
thank you for the great article. It is a good introduction to the paint function of the CTreeCtrl. I tried to extend your control by a highlighting every second line (Background-Color == Windows HIGHLIGHTED). Unfortunately drawing the background color of the whole item rectangle (GetItemRect(hItem, &rect, FALSE)) paint over the item icon and expand/collapse icon.
Do you have any suggestion how this could be fixed?
Greetz
Daniel
|
|
|
|
 |
|
 |
Hi,
When i click m_Tree.SetItemColor(htItem,RGB(0,0,0));
then the text become garbage characters.
this issue does not occur in english or any other single byte language.
please help
thanks
yotam
|
|
|
|
 |
|
 |
When working with this, it worked well but there are a few draw backs resulting from having to draw the text on top of MFC's text: the text will need to be shifted for larger windows fonts, and I have noticed an issue on a foreign system with the text not lining up properly. Here is another way to do this within the drawing frame work in place by using custom drawing:
Override OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult):
In the header, add
afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
In Message Map, add
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)
Then in the OnCustomDraw() function, you can tell it to loop through the items with each call and access each item individually setting the font color.
This microsoft article is helpful with explaining the process of handling prepainting, postpainting, etc. and it tells what results to pass back to control the behavior: http://msdn.microsoft.com/en-us/library/bb761817(VS.85).aspx#list_tree[^]
To change an items color, cast the NMHDR structure:
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
Handle each painting case as described in the article and change color in CDDS_ITEMPREPAINT. To loop through each item with subsequent OnCustomDraw() calls, return CDRF_NOTIFYSUBITEMDRAW in the CDDS_PREPAINT stage:
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
{
HTREEITEM hTreeItem = (HTREEITEM)lplvcd->nmcd.dwItemSpec;
lplvcd->clrText = RGB(225,0,0);
*pResult = CDRF_NEWFONT;
break;
}
case CDDS_ITEMPOSTPAINT:
*pResult = CDRF_DODEFAULT;
break;
default:
*pResult = CDRF_DODEFAULT;
break;
}
Hope this helps...
mike
|
|
|
|
 |
|
|
 |
|
 |
Actually, I need the Colorful TreeView in my project. but i can't find it....so sadly.
|
|
|
|
 |
|
 |
Hi
nice article, now if I want to use a CTreeView (that is, I don't want to use a 'resource', but use in a View directly), the CTreeView as its own default tree, accessed by GetTreeCtrl(), but what to do if I want to use this CTreeCtrlEx instead of the default onw in my derived CTreeView class? Thanks!
Mat
|
|
|
|
 |
|
 |
Thanks for the class: CTreeCtrlEx. There are no license restrictions listed on code project, for using this control. Are you imposing any?
Thanks a bunch.
Clint
|
|
|
|
 |
|
 |
When I updated the color of a string it wasn't updated directly on the screen. I had to minimize the window, select and then deselect the item or a similiar action for the change to show.
I solved this by calling m_MyCTreeCtrlExVariable.Invalidate(); and then m_MyCTreeCtrlExVariable.UpdateWindow(); after I changed a node. This forces the change to show on the screen. I'm just posting this in case someone else has the same problem and don't know how to solve it.
Btw. Thanks for a very useful class.
|
|
|
|
 |
|
 |
They must be redefined, else strange effects are possible.
BOOL CTreeCtrlEx::DeleteItem(HTREEITEM hItem)
{
m_mapColorFont.RemoveKey(hItem);
return ((CTreeCtrl*) this)->DeleteItem( hItem );
}
BOOL CTreeCtrlEx::DeleteAllItems()
{
m_mapColorFont.RemoveAll();
return ((CTreeCtrl*) this)->DeleteAllItems();
}
|
|
|
|
 |
|
 |
Christoph Conrad wrote: BOOL CTreeCtrlEx::DeleteItem(HTREEITEM hItem)
{
m_mapColorFont.RemoveKey(hItem);
return ((CTreeCtrl*) this)->DeleteItem( hItem );
}
BOOL CTreeCtrlEx::DeleteAllItems()
{
m_mapColorFont.RemoveAll();
return ((CTreeCtrl*) this)->DeleteAllItems();
}
Thanks for the bugfix. You can use an easier notation:
BOOL CTreeCtrlEx::DeleteItem(HTREEITEM hItem)
{
m_mapColorFont.RemoveKey(hItem);
return CTreeCtrl::DeleteItem( hItem );
}
BOOL CTreeCtrlEx::DeleteAllItems()
{
m_mapColorFont.RemoveAll();
return CTreeCtrl::DeleteAllItems();
}
|
|
|
|
 |
|
 |
If a bold string exceeds the tree's client area no horizontal scrollbar is displayed when the same text non-bold doesn't exceed the client area.
|
|
|
|
 |
|
 |
I would like to use CTreeCtrlEx with custom highlight colors, not the system colors used by CTreeCtrl. I found an example of how to do this for a list control:
http://www.codeguru.com/Cpp/controls/listview/dragdrop/article.php/c4193/[^]
But I do not understand the custom draw mechanism and other things about this example well enough to apply it to a tree control.
Anyone who knows how to do this willing to give me some help?
|
|
|
|
 |
|
 |
how to i change the selected item's background and forground color?
|
|
|
|
 |
|
 |
Can you set a TEXT BACKGROUND COLOR in this control? What would i have to change to allow this?
If i change the background color of the treebox to grey, the text seems to still remain on a white background. Any suggestions??
-Kevin
|
|
|
|
 |
|
 |
The OnPaint method contains the following instruction:
memDC.SetBkColor(GetSysColor(COLOR_WINDOW));
You have to change it with
memDC.SetBkColor( GetBkColor() );
Then you can set the background of your tree control using SetBkColor method
|
|
|
|
 |
|
 |
wow terrific!!!
thank you soo much. works like a charm
-Kevin
|
|
|
|
 |
|
 |
The solution suggested by Samuele above will only set the correct background in the case of a custom-coloured tree control, but will not work for default-coloured list control.
To make a more general fix that will work in all such cases, add these lines: if (GetBkColor() == (COLORREF)-1)
{
memDC.SetBkColor(GetSysColor(COLOR_WINDOW));
}
else
{
memDC.SetBkColor(GetBkColor());
}
instead of the line that Samuele mentioned: memDC.SetBkColor(GetSysColor(COLOR_WINDOW)); GetBkColor() returns -1 if no explicit colour has been applied, i.e. the tree control is using the system color for the background color.
I hope this helps a little.
--
/stokos
|
|
|
|
 |
|
 |
If the function GetBkColor fails, the return value is CLR_INVALID.
Is '(COLORREF)-1' equivalent to 'CLR_INVALID'?
Sam
|
|
|
|
 |
|
 |
Yes.
CLR_INVALID is defined as (in wingdi.h):
#define CLR_INVALID 0xFFFFFFFF This hex value is equivalent to -1.
However, the GetBkColor() function used in the code is the one for the tree control, not the GDI function (otherwise, it would be written as ::GetBkColor()).
I hope this helps.
--
/stokos
|
|
|
|
 |
|
 |
You're right.
Here the definition of the method from "MSDN bible"...
CTreeCtrl::GetBkColor
COLORREF GetBkColor( ) const;
Return Value
A COLORREF value that represents the current background color. If this value is -1, the control is using the system color for the background color.
|
|
|
|
 |
|
 |
For supporting Japanese and chinese in my project, i have enabled IME support..... but in tree control while renaming the node ( i could insert the japanese char text as tree node ) i couldnt enter japanese. i think the reason is CTreeCtrl provides a CEdit for entering text while we rename a node....!!! How can i enter japanese in tree control while renaming it ????
tamaaaaaaaar...!! slathak..!!!
|
|
|
|
 |
|
 |
Use SetImageList only can add 16-color image to the treectrl.
How to display a turecolor image or icon in the treectrl?
|
|
|
|
 |
|
 |
If I change the Items height in the tree the colored text is misplaced!
This lines fixes that:
int height = GetItemHeight();
memDC.TextOut(rect.left + 2, rect.top + (height - 16)/2+ 1, sItem);
Instead of:
memDC.TextOut(rect.left + 2, rect.top + 1, sItem);
|
|
|
|
 |
|
 |
I use your class in my project,SetItemSold can success,but SetItemColor can not
success,why????
Need I set parameter?
thanks!!!1
|
|
|
|
 |
|
 |
http://www.exontrol.com/sg.jsp?content=products/extree
Regards,
Mike(langelo)
|
|
|
|
 |