15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Enhancing CTreeCtrl?!

Tim Philip -- philip@cs.usask.ca
Monday, April 15, 1996


Platform: VC4.0, WinNT or Win95

Hi!

I sent a message to the list last week about owner-drawing the CTreeCtrl
or anything else that can be done to change the colour of each node.

I haven't received any response yet, but I have received several queries
as to whether or not I've found a solution yet.  No, I haven't.  So
I thought I'd post again.

Question:  Does anyone know of anyway to enhance the CTreeCtrl?  In
particular, I would like to have nodes of different colour text in
the tree.  I don't see any way to owner-draw the control which
really surprises me given the awesome control of the CListBox.
I'm really hoping there is some other way to enhance the Tree Control
but I haven't been able to find it.  

Any ideas or confirmation of its limitations would be GREATLY
appreciated!

Thanks!

Tim.

-------
Tim Philip, B.Sc.           Randco Software Corporation
Consultant                  2530 Hanover Avenue   
                            Saskatoon, SK          Phone: +1-306-343-3380
philip@cs.usask.ca          Canada   S7J 1G1         Fax: +1-306-343-3341



Mike Blaszczak -- mikeblas@msn.com
Wednesday, April 17, 1996

[Mini-digest: 3 responses]

> Platform: VC4.0, WinNT or Win95

Thanks.

> ... last week ...
> I haven't received any response yet, but I have received several queries
> as to whether or not I've found a solution yet.  No, I haven't.  So
> I thought I'd post again.

If timely replies are important to you, you should consider using an official 
support mechansim.  While MFC-L is useful, it is _not_ an official, timely way 
to get support for MFC as a Microsoft product.  People here answer questions 
for you as they have time to do so.

> Question:  Does anyone know of anyway to enhance the CTreeCtrl?

CTreeCtrl is not to blame here: the Windows common tree control is. Windows 
does not support owner-drawn tree controls and does not support multiple 
selection tree controls.  MFC does not attempt to fix this shortcoming of 
Windows.

> I'm really hoping there is some other way to enhance the Tree Control
> but I haven't been able to find it.  

You'll either have to completely draw the content of the tree control from 
scratch using your own code, or you'll have to purchase a third-party tree 
control.  If you wait, you might find that Windows enhances the common tree 
control to have swome of the features you're looking for.

.B ekiM
TCHAR szPlayoffs[] = _T("Look!  A skating zebra!");
-----From: Deepak Saxena 


Text item: 


hmmm...haven't tried this, but here's a wild guess.  When you add an item to the
tree control, you can set the text value to a certain value(see docs for 
CTreeCtrl::InsertItem() for exact name) that will make the tree send a WM_NOTIFY
message to whoever the parent is.  In this message you would normally just set 
the text member of the TREE_ITEM structure to whatever you want.  But...what if 
in addition to doing so, you also call SetTextColor() on the DC for the 
CTreeCtrl?!  Assuming that the standard win32 implementation of the ctrl doesn't
call SetTextColor() and uses the default color, you should see a different color
of text.  Just do this for all your items and it might just work....do keep me 
posted :)

Another option...very convuluted in my opinion....find out what font the 
treectrl is using.  Create a compatible DC in memory...paint the background 
white, draw the text, and then blit the text to the item rectangle.  When you 
add the item to the window, just set the bitmap value to a callback and don't 
use the text parameter.  In the WM_NOTIFY handler that handles choosing the 
bitmap, set the bitmap to one that is basically a transperent bitmap(create a 
compatible DC in mem and then paint it with a HOLLOW_BRUSH) so that your changes
won't be erased. Now, call GetItemRect to get the top-left corner of the item 
area and then do a BltBlt of your text image to the treectrl DC.

Sorry for not giving more descriptive names of variable settings and function 
calls, but I don't have the docs on me at the moment :(

--
Deepak_Saxena@ccm.ch.intel.com         | On June 30, 1996:
http://cernan.ecn.purdue.edu/~deepak   |     The Electronic Freedom 
Home:(602)812-8933, Work:(602)554-1304 |       March On Washington      
My opinions, not Intel's!              | http://www.efm.org

-----From: "Robert M. Teague" 

I haven't seen anything specific along this line. However, you might see
"Extending the MFC Library" by David Schmitt. It has an execellent
home-grown example of a CTreeCtrl control along with source code.

Robert M. Teague
teague@primenet.com





| Вернуться в корень Архива |