Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
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 Long
Private Const GWL_STYLE = -16&
Private Const TVM_SETBKCOLOR = 4381&
Private Const TVM_GETBKCOLOR = 4383&
Private Const TVS_HASLINES = 2&
Dim frmlastForm As Form
Private Sub Form_Load()
Dim nodX As Node
Me.Show
DoEvents
For i = 1 To 100
Set nodX = treeview1.Nodes.Add(, , "R" & i, "Root")
nodX.ForeColor = RGB(80, 0, 255)
Next
nodX.EnsureVisible
treeview1.style = tvwTreelinesText ' Style 4.
treeview1.BorderStyle = vbFixedSingle
End Sub
Private Sub Command1_Click()
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)
End Sub