Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As LongPrivate Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Const GWL_STYLE = -16&
Private Const TVM_SETBKCOLOR = 4381&
Private Const TVM_GETBKCOLOR = 4383&
Private Const TVS_HASLINES = 2&改变背景色
Dim lngStyle As Long
Call SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(255, 0, 0))
'改变背景到红色lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle - TVS_HASLINES)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle)
Private Const TVM_SETBKCOLOR = 4381&
Private Const TVM_GETBKCOLOR = 4383&
Private Const TVS_HASLINES = 2&改变背景色
Dim lngStyle As Long
Call SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(255, 0, 0))
'改变背景到红色lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle - TVS_HASLINES)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle)
Private Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Const GWL_STYLE = -16
Private Const TVM_SETBKCOLOR = 4381
Private Const TVM_SETTEXTCOLOR = 4382
Private Const TVM_GETBKCOLOR = 4383
Private Const TVS_HASLINES = 2
Private Sub Form_Load()
Dim NodeX As Node
Dim lngStyle As Long
Call SendMessage(TreeView1.hWnd, TVM_SETBKCOLOR, 0, ByVal RGB(240, 240, 240))
lngStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle - TVS_HASLINES)
Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, lngStyle)
With TreeView1.Nodes
.Add , , "Root", "Root"
.Add "Root", tvwChild, , "Node1"
.Add "Root", tvwChild, , "Node2"
.Add "Root", tvwChild, , "Node3"
.Add "Root", tvwChild, , "Node4"
End With
For Each NodeX In TreeView1.Nodes
With NodeX
.BackColor = RGB(240, 240, 240)
.ForeColor = vbBlue
End With
Next
End Sub
TVM_SETBKCOLOR
wParam = 0;
lParam = (LPARAM)(COLORREF) clrBk;Sets the background color of the control. You can send this message explicitly or by using the TreeView_SetBkColor macro. Returns a COLORREF value that represents the previous background color. If this value is -1, the control was using the system color for the background color.
clrBk
COLORREF value that contains the new background color. If this value is -1, the control will revert to using the system color for the background color.
Version 4.71 See also TVM_GETBKCOLOR TVM_SETTEXTCOLOR
TVM_SETTEXTCOLOR
wParam = 0;
lParam = (LPARAM)(COLORREF) clrText;Sets the text color of the control. You can send this message explicitly or by using the TreeView_SetTextColor macro. Returns a COLORREF value that represents the previous text color. If this value is -1, the control was using the system color for the text color.
clrText
COLORREF value that contains the new text color. If this argument is -1, the control will revert to using the system color for the text color.
Version 4.71 See also TVM_GETTEXTCOLOR