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

Treeviewitem

50 views
Skip to first unread message

Roland Skottke

unread,
May 2, 2002, 6:15:59 AM5/2/02
to
Hi,

i have problems to set the background colors from a treeview to the
treeviewitem.
can anybody help?

greatings

Roland


Geoff Schaller

unread,
May 2, 2002, 6:27:51 AM5/2/02
to
Roland,

Here is one way - there are others. The reference to SELF:SplitTreeView is
obviously an ivar holding my treeview. Just replace this reference with
yours. I also included some structures in case your VO does not have them. I
have also used direct RGB values but you could make these runtime
selectable.

Geoff

METHOD ControlNotify( oEvent ) CLASS MySplitWindow

LOCAL pNMCustomDraw AS _WINNMTVCUSTOMDRAW
LOCAL dwDrawStage AS LONG
LOCAL dwItem AS DWORD
LOCAL oItem AS TreeViewItem
LOCAL symItem AS SYMBOL

DO CASE
CASE oEvent:NotifyCode = NM_CUSTOMDRAW
pNMCustomDraw := PTR( _CAST , oEvent:lParam )
dwDrawStage := pNMCustomDraw.nmcd.dwDrawStage
DO CASE
CASE dwDrawStage = CDDS_PREPAINT
SELF:EventReturnValue := CDRF_NOTIFYITEMDRAW
CASE dwDrawStage = CDDS_ITEMPREPAINT
dwItem := pNMCustomDraw.nmcd.dwItemSpec
symItem := SELF:SplitTreeView:__GetSymbolFromHandle(PTR( _CAST ,
dwItem ))
oItem := SELF:SplitTreeView:GetItemAttributes( symItem )
IF _and( pNMCustomDraw.nmcd.uItemState , CDIS_SELECTED ) > 0
pNMCustomDraw.clrText := RGB( 255, 255, 255 )
pNMCustomDraw.clrTextBk := RGB( 0, 0, 128 )
ELSE
pNMCustomDraw.clrText := RGB( 0 , 0 , 0 )
pNMCustomDraw.clrTextBk := RGB( 165 , 255 , 255 )
ENDIF
SELF:EventReturnValue := CDRF_NEWFONT
OTHERWISE
SELF:EventReturnValue := CDRF_DODEFAULT
ENDCASE
SetWindowLong( SELF:Handle() , DWL_MSGRESULT , SELF:EventReturnValue )
RETURN SELF:EventReturnValue
OTHERWISE
SUPER:ControlNotify(oEvent)
ENDCASE
RETURN 0

STRUCT _WINNMTTCUSTOMDRAW
MEMBER nmcd IS _WINNMCUSTOMDRAW
MEMBER uDrawFlags AS DWORD
STRUCT _WINNMLVCUSTOMDRAW
MEMBER nmcd IS _WINNMCUSTOMDRAW
MEMBER clrText AS DWORD
MEMBER clrTextBk AS DWORD
MEMBER iSubItem AS INT

DEFINE NM_CUSTOMDRAW := (NM_FIRST-12)
STRUCT _WINNMTVCUSTOMDRAW
MEMBER nmcd IS _WINNMCUSTOMDRAW
MEMBER clrText AS DWORD
MEMBER clrTextBk AS DWORD
MEMBER iLevel AS INT


Arie van Burgsteden

unread,
May 2, 2002, 3:43:03 PM5/2/02
to

Roland,

Roland,

You can use a Windows API function. Unlike the listview class the treeview
doesn't have a Access/Assign of it's own to set the backgroundcolor
correctly.
This is what i use, it sets the backgroundcolor for the treeview and the
treeviewitems at once.

Arie.

oTv:BackgroundColor := Color{ 255, 255, 200}

ASSIGN backgroundColor(oColor) CLASS MyTreeview
LOCAL hwndTV AS PTR
LOCAL liStyle AS LONG
hwndTV := SELF:Handle()

TreeView_SetBkColor(hwndTV, oColor:ColorRef) // Sets the background
color

liStyle := GetWindowLong(hwndTV, GWL_STYLE)
IF _and(liStyle,TVS_HASLINES) != 0 // If the treeview style is HASLINE
reshow treeview
SetWindowLong(hwndTV, GWL_STYLE, _xor(liStyle,TVS_HASLINES))
SetWindowLong(hwndTV, GWL_STYLE, liStyle)
ENDIF
RETURN NIL


ACCESS BackgroundColor CLASS MyTreeView
VTrace VMethod

RETURN Color{TreeView_GetBkColor(SELF:Handle())}

Roland Skottke

unread,
May 3, 2002, 4:49:05 AM5/3/02
to
Hi Arie,

thank you for answere, but the Functions

TreeView_SetBkColor()
TreeView_GetBkColor()

are missing. (I works with XP)

greatings

Roland

Roland Skottke

unread,
May 3, 2002, 4:21:50 AM5/3/02
to
Hi Geoff,

your code works fine.

thank you

Roland


Roland Skottke

unread,
May 3, 2002, 6:15:08 AM5/3/02
to
Geoff,

your Code works fine, if you have a treeview with an imagelist.
But I have also treeviews without an imagelist. There is a blanc place.
Have you for this version also a peace of code?

thanks in advance

Roland


Geoff Schaller

unread,
May 3, 2002, 7:12:30 AM5/3/02
to
Treeviews without images, hmmm, have to think about that <g>.

As far as I knew, all treeviews had images <g>. ...but I take your point. I
confess I have not tried this so I am not sure what the answer is there.

Geoff

"Roland Skottke" <Sko...@t-online.de> wrote in message
news:aatnv3$3ds$04$1...@news.t-online.com...

Roland Skottke

unread,
May 3, 2002, 7:40:20 AM5/3/02
to
OK Geoff,

I will paint colored images with + and - sign and place on the blancs. <g>

Roland

Geoff Schaller

unread,
May 3, 2002, 7:50:44 AM5/3/02
to
<bg>

(I think you get these OK with or without images)


"Roland Skottke" <Sko...@t-online.de> wrote in message

news:aatsur$8pg$04$1...@news.t-online.com...

Arie van Burgsteden

unread,
May 3, 2002, 11:47:43 AM5/3/02
to

Roland,

Here they are,

Arie

FUNCTION TreeView_GetBkColor( hwnd AS PTR ) AS DWORD PASCAL
RETURN DWORD( _CAST , SendMessage( hwnd , TVM_GETBKCOLOR , 0 , 0L ) )

FUNCTION TreeView_SetBkColor( hwnd AS PTR , clr AS DWORD ) AS DWORD PASCAL
RETURN DWORD( _CAST , SendMessage( hwnd , TVM_SETBKCOLOR , 0 , LONG(_CAST,
clr ) ) )

DEFINE TVM_GETBKCOLOR := (TV_FIRST + 31)
DEFINE TV_FIRST := 0x1100
DEFINE TVM_SETBKCOLOR := (TV_FIRST + 29)

"Roland Skottke" <Sko...@t-online.de> wrote in message

news:aatldk$t3a$02$2...@news.t-online.com...

0 new messages