Make a node in a VB6 treeview italic

2.1k views Asked by At

I'd like be able to make the text on individual nodes in a treeview italic. It sounds simple but I haven't been able to find out how. There is no property on the node that allows it. I can make it bold or change the color or set the background color but not make it italic. Does anyone know how to do this?

2

There are 2 answers

0
Steve Massing On

You are correct that it sounds simple. Sadly, however, it's not so simple to do in reality. The treeview control in VB6 is wrapper around the common controls treeview, but it does not expose much of the functionality of the control. You can do what you want by subclassing the control and handling the item paint event as owner draw. I don't have a VB6 IDE set up handy, but here are a couple of good resources for you to check out:

Brad Martinez's website on VB6 Hardcore tips:
http://btmtz.mvps.org/treeview/

and my personal favorite:
Steve McMahon's VBAccerator website
http://www.vbaccelerator.com/home/VB/Code/Controls/TreeView/TreeView_Control/article.asp which has a very nice custom control implementation that you can drop right into your project, source code and all.

These two website are indispensible for VB6 development along with Karl Peterson's site: http://vb.mvps.org/

Good luck!

0
wqw On

There is no easy way to make this. Basicly you have to:

  • use TreeView control from Microsoft Windows Common Controls 5.0 (SP2)
  • subclass control's hWnd
  • on OCM_NOTIFY message check for NM_CUSTOMDRAW
    • on stage CDDS_PREPAINT return CDRF_NOTIFYITEMDRAW
    • on stage CDDS_ITEMPREPAINT select custom font in passed hDC and return CDRF_NEWFONT

There is no easy way to get hItem from treeview node either. I'm using this hackish way:

Private Function pvGetHItem(oNode As ComctlLib.Node) As Long
    Call CopyMemory(pvGetHItem, ByVal ObjPtr(oNode) + 68, 4)
End Function