ツリービュー の前景色・背景色を設定

何でツリービューってForeColor,BackColorプロパティがないんだろう・・・。




Option Explicit

Private Const TV_FIRST As Long = &H1100
Private Const TVM_SETBKCOLOR  As Long = (TV_FIRST + 29)
Private Const TVM_SETTEXTCOLOR As Long = (TV_FIRST + 30)

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hWnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any _
) As Long

Private Declare Function OleTranslateColor Lib "oleaut32.dll" ( _
    ByVal lOleColor As Long, _
    ByVal lHPalette As Long, _
    ByRef lColorRef As Long _
) As Long

Public Sub TreeView_SetColor(tvw As TreeView, ByVal nForeColor As OLE_COLOR, ByVal nBackColor As OLE_COLOR)
    Dim nStyle As Long
    Dim nd As Node
    Call OleTranslateColor(nForeColor, 0&, nForeColor)
    Call OleTranslateColor(nBackColor, 0&, nBackColor)

    With tvw
        nStyle = .Style
        Call SendMessage(.hWnd, TVM_SETTEXTCOLOR, 0, ByVal nForeColor)
        Call SendMessage(.hWnd, TVM_SETBKCOLOR, 0, ByVal nBackColor)
        .Style = 0
        .Style = nStyle
        For Each nd In .Nodes
            nd.BackColor = nBackColor
            nd.ForeColor = nForeColor
        Next
    End With
End Sub