Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB6
Expertise: Intermediate
Mar 3, 2001



Application Security Testing: An Integral Part of DevOps

SetTreeViewBackColor - Change the background color of a TreeView control

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As _
    Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd _
    As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd _
    As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Const GWL_STYLE = -16&
Const TVM_SETBKCOLOR = 4381&

Sub SetTreeViewBackColor(TV As TreeView, ByVal BackColor As Long)
    Dim lStyle As Long
    Dim TVNode As node
    ' set the BackColor for every node
    For Each TVNode In TV.Nodes
        TVNode.BackColor = BackColor

    ' set the BackColor for the TreeView's window
    SendMessage TV.hwnd, TVM_SETBKCOLOR, 0, ByVal BackColor
    ' get the current style
    lStyle = GetWindowLong(TV.hwnd, GWL_STYLE)
    ' temporary hide lines
    SetWindowLong TV.hwnd, GWL_STYLE, lStyle And (Not TVS_HASLINES)
    ' redraw lines
    SetWindowLong TV.hwnd, GWL_STYLE, lStyle
End Sub
Marco Bellinaso
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date