改变 treeview 的背景
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
set nodx = treeview1.nodes.add(, , “r”, “root”)
set nodx = treeview1.nodes.add(“r”, tvwchild, “c1”, “child 1”)
set nodx = treeview1.nodes.add(“r”, tvwchild, “c2”, “child 2”)
set nodx = treeview1.nodes.add(“r”, tvwchild, “c3”, “child 3”)
set nodx = treeview1.nodes.add(“r”, tvwchild, “c4”, “child 4”)
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
option explicit
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&
private sub form_load()
dim nodex as node
dim i as integer
dim lstyle as long
call sendmessage(treeview1.hwnd, tvm_setbkcolor, 0, byval rgb(255, 0, 0))
lstyle = getwindowlong(treeview1.hwnd, gwl_style)
call setwindowlong(treeview1.hwnd, gwl_style, lstyle – tvs_haslines)
call setwindowlong(treeview1.hwnd, gwl_style, lstyle)
treeview1.style = tvwtreelinesplusminuspicturetext
treeview1.borderstyle = ccfixedsingle
with treeview1.nodes
set nodex = .add(, , “r”, “root”)
nodex.backcolor = rgb(255, 0, 0)
for i = 1 to 10
set nodex = .add(“r”, tvwchild, “c” & i, “child ” & i)
nodex.backcolor = rgb(255, 0, 0)
nodex.ensurevisible
next
end with
end sub