I would like to give you more comments on an image and a download!
.
.
,
,
Download test:
New:
Http://files.cnblogs.com/starwork/dsTreeView2.rar
Old:
Http://files.cnblogs.com/starwork/dsTreeView.rar
Pay a method to load the Treeview:
Create a custom control: mytreeview, usercontrol. autoredraw = true, usercontrol. scalemode = 3
The mytreeview code starts:
Option explicit
Private htree as long
Private inodes as long
Private const id_treeview = 1000
Private type tvwnode
Hitem as long
Hparent as long
Index as long
Key as string
Text as string
Tag as string
End type
Private nodex () as tvwnode
Public Enum relationconstants
Tvwsort
Tvwfirst
Tvwlast
Tvwchild
End Enum
Private const TV _first = & h1100
Private const tvm_getitem = (TV _first + 12)
Private const tvm_getnextitem = (TV _first + 10)
Private const tvm_insertitem = (TV _first + 0)
Private const tvm_setitem = (TV _first + 13)
Private const tvm_deleteitem = (TV _first + 1)
Private const tvs_hasbuttons = & H1
Private const tvs_haslines = & H2
Private const tvs_linesatroot = & h4
Private const tvm_getcount = (TV _first + 5)
Private const tvif_param = & h4
Private const tvif_state = & H8
Private const tvif_text = & H1
Private const ws_border = & h800000
Private const ws_child = & h40000000
Private const ws_visible = & h0000000
Private type tvitemex
Mask as long
Hitem as long
State as long
Statemask as long
Psztext as string
Cchtextmax as long
Iimage as long
Iselectedimage as long
CChildren as long
Lparam as long
Iintegral as long
End type
Private type tvinsertstruct
Hparent as long
Hinsertafter as long
Item as tvitemex
End type
Private const tvi_root = & hffff0000
Const tvgn_parent as long = & h3
Private declare function create‑wex lib "USER32" alias "create‑wexa" (byval dwexstyle as long, byval lpclassname as string, byval lpwindowname as string, byval dwstyle as long, byval X as long, byval y as long, byval nwidth as long, byval nheight as long, byval hwndparent as long, byval hmenu as long, byval hinstance as long, lpparam as any) as long
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 sendmessagelong lib "USER32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, byval lparam as long) as long
Private declare function initcommoncontrolsex lib "comctl32.dll" (byref icx as taginitcommoncontrolsex) as long
Private type taginitcommoncontrolsex
Size as long
Initwhat as long
End type
Private const icc_treeview_classes = 2 &
Private sub createtree (hparent as long)
Dim hcont as long
Hcont = createmediawex (0 &, "static", "btreeviewclass", ws_border or ws_visible or ws_child, 0, 0, usercontrol. scalewidth, usercontrol. scaleheight, hparent, 0, app. hinstance, 0)
Htree = createmediawex (0 &, "systreeview32", "", ws_visible or ws_child or tvs_haslines or tvs_hasbuttons or tvs_linesatroot, 0, 0, usercontrol. scalewidth, usercontrol. scaleheight, hcont, id_treeview, app. hinstance, 0)
End sub
Public Function tvwadditem (hrelitem as long, relation as long, text as string) as long
Dim tvin as tvinsertstruct, hrel as long, TVI as tvitemex
If hrelitem = 0 then hrelitem = 0 &
If typename (hrelitem) = "long" then
Hrel = hrelitem
End if
Tvin. hparent = hrel
Tvin. item. Mask = tvif_text or tvif_state
Tvin. item. psztext = text & CHR $ (0)
Tvin. item. cchtextmax = Len (text) + 1
If relation = tvwchild then
Tvin. hparent = sendmessagelong (htree, tvm_getnextitem, tvgn_parent, hrel)
End if
Hrel = sendmessage (htree, tvm_insertitem, 0, tvin)
If hrel <> 0 then
Sendmessage htree, tvm_getitem, hrel, TVI
TVI. Mask = tvif_param
TVI. lparam = hrel
Sendmessage htree, tvm_setitem, hrel, TVI
Redim preserve nodex (inodes)
Inodes = inodes + 1
End if
Tvwadditem = hrel
End Function
Public Function getcount () as long
Getcount = sendmessage (htree, tvm_getcount, tvgn_parent, & O0)
End Function
Public sub cleartree ()
Lockwindow true, frmmain
Sendmessagelong htree, tvm_deleteitem, 0, tvi_root
Lockwindow false, frmmain
End sub
Private sub usercontrol_initialize ()
Dim icx as taginitcommoncontrolsex
Icx. size = Len (icx)
Icx. initwhat = icc_treeview_classes
Initcommoncontrolsex icx
End sub
Private sub usercontrol_resize ()
Createtree usercontrol. hwnd
End sub
Add a form: frmmain
Put command1 and a mytreeview
Code start:
Option explicit
Dim lastparent as long
Private sub commandementclick ()
Dolog mytreeview1, "ABC", false, true
End sub
Public sub dolog (tview as mytreeview, logtext as string, ischild as Boolean, optional adddate as Boolean = false)
With tview
If ischild = false then
Lastparent = tview. tvwadditem (0, 0, logtext)
If adddate then dolog tview, "Time:" & now, true, false
End
End sub
The above is a simple example. I hope you can make better results! Thank you!