Results 1 to 2 of 2

Thread: api call to change control colors

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Posts
    83

    Thumbs up

    i posted another message on how to change the Foreground and background colors of the TreeView control.

    and i got the following reply:

    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&
    Const TVS_HASLINES = 2&

    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
    Next

    ' 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


    ----------------------------------------------
    i used it and it worked
    but the response only included how to change the backcolor not the forecolor


    and also, there is the opaque style behind the text which is the same color as the background

    so when the background color is changed with the above code the area behind the text is still white (or whetever the back was...)

    so i really need to find out how to change the forecolor (text) and the area behind the text..

    thx
    sphynx

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2001
    Posts
    83

    nevemind..

    never mind i figured it out

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width