改变 TreeView 的背景 Private Declare Function SendMessage Lib User Alias SendMessageA (ByVal hWnd As Long ByVal wMsg As Long ByVal wParam As Long lParam As Long) As Long Private Declare Function GetWindowLong Lib User Alias GetWindowLongA (ByVal hWnd As Long ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib User Alias SetWindowLongA (ByVal hWnd As Long ByVal nIndex As Long ByVal dwNewLong As Long) As Long Private Const GWL_STYLE = & Private Const TVM_SETBKCOLOR = & Private Const TVM_GETBKCOLOR = & Private Const TVS_HASLINES = & Dim frmlastForm As Form Private Sub Form_Load() Dim nodX As Node Set nodX = TreeViewNodesAdd( R Root) Set nodX = TreeViewNodesAdd(R tvwChild C Child ) Set nodX = TreeViewNodesAdd(R tvwChild C Child ) Set nodX = TreeViewNodesAdd(R tvwChild C Child ) Set nodX = TreeViewNodesAdd(R tvwChild C Child ) nodXEnsureVisible TreeViewstyle = tvwTreelinesText Style TreeViewBorderStyle = vbFixedSingle End Sub Private Sub Command_Click() Dim lngStyle As Long Call SendMessage(TreeViewhWnd TVM_SETBKCOLOR ByVal RGB( )) 改变背景到红色 lngStyle = GetWindowLong(TreeViewhWnd GWL_STYLE) Call SetWindowLong(TreeViewhWnd GWL_STYLE lngStyle TVS_HASLINES) Call SetWindowLong(TreeViewhWnd GWL_STYLE lngStyle) End Sub Option Explicit Private Declare Function SendMessage Lib User Alias SendMessageA (ByVal hWnd As Long ByVal wMsg As Long ByVal wParam As Long lParam As Long) As Long Private Declare Function GetWindowLong Lib User Alias GetWindowLongA (ByVal hWnd As Long ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib User Alias SetWindowLongA (ByVal hWnd As Long ByVal nIndex As Long ByVal dwNewLong As Long) As Long Private Const GWL_STYLE = & Private Const TVM_SETBKCOLOR = & Private Const TVM_GETBKCOLOR = & Private Const TVS_HASLINES = & Private Sub Form_Load() Dim nodex As Node Dim i As Integer Dim lStyle As Long Call SendMessage(TreeViewhWnd TVM_SETBKCOLOR ByVal RGB( )) lStyle = GetWindowLong(TreeViewhWnd GWL_STYLE) Call SetWindowLong(TreeViewhWnd GWL_STYLE lStyle TVS_HASLINES) Call SetWindowLong(TreeViewhWnd GWL_STYLE lStyle) TreeViewStyle = tvwTreelinesPlusMinusPictureText TreeViewBorderStyle = ccFixedSingle With TreeViewNodes Set nodex = Add( R Root) nodexBackColor = RGB( ) For i = To Set nodex = Add(R tvwChild C & i Child & i) nodexBackColor = RGB( ) nodexEnsureVisible Next End With End Sub |