Ticket #394: treetest.au3

File treetest.au3, 2.5 KB (added by Wooltown, 13 years ago)
Line 
1#Include <TreeViewConstants.au3>
2#Include <WindowsConstants.au3>
3#include <GUIConstantsEx.au3>
4#Include <GuiTreeView.au3>
5Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
6Opt("GUICloseOnESC",1)
7
8Global  $treeView, $item[10][10]
9GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
10GUICreate("TreeView Test",200,400)
11
12$treeView = GUICtrlCreateTreeView(10,10,180,380,BitOr($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_DISABLEDRAGDROP,$TVS_SHOWSELALWAYS,$TVS_CHECKBOXES,$TVS_TRACKSELECT),$WS_EX_CLIENTEDGE )
13
14For $x = 0 to 9
15        $item[$x][0] = GUICtrlcreateTreeViewItem("Item" & $x ,$treeView)
16        For $y = 1 to 9
17                $item[$x][$y] = GUICtrlcreateTreeViewItem("Item" & $x & "-" & $y,$item[$x][0])
18        Next
19Next
20GUISetOnEvent($GUI_EVENT_CLOSE, "GUIExit")
21GUISetState()
22
23While 1
24        Sleep(100)
25Wend
26
27;==================================================================================================================
28Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
29        #forceref $hWndGUI, $MsgID, $wParam
30        Local $tagNMHDR, $event, $hwndFrom, $code
31        $tagNMHDR = DllStructCreate("int;int;int", $lParam) ;NMHDR (hwndFrom, idFrom, code)
32        If @error Then Return
33        $event = DllStructGetData($tagNMHDR, 3)
34        $xx = DllStructGetData($tagNMHDR, 1)
35        $yy = DllStructGetData($tagNMHDR, 2)
36        Select
37        Case $wParam = $treeview
38                Select
39                        Case $event = $NM_CLICK
40                                TreeView_Click()       
41                               
42                        EndSelect
43        EndSelect
44        ; Proceed the default Autoit3 internal message commands.
45        ; You also can complete let the line out.
46        ; !!! But only 'Return' (without any value) will not proceed
47        ; the default Autoit3-message in the future !!!
48        Return $GUI_RUNDEFMSG
49EndFunc   ;==>WM_Notify_Events
50;==================================================================================================================
51Func TreeView_Click()   
52        $hItem = _GUICtrlTreeView_GetSelection($TreeView)
53        If $hitem = "0x00000000" Then
54                Msgbox(0,"First click",$hItem)
55        EndIf
56        $l_TCname = _GUICtrlTreeView_GetText($TreeView,$hItem)
57        $l_Child = _GUICtrlTreeView_GetParentHandle(GUICtrlGetHandle($TreeView),$hItem)
58        ;Msgbox(0,"",$l_Child)
59        If String($l_Child) = String("0x00000000") Then
60                ;msgbox(0,"root","")
61                _GUICtrlTreeView_SetChecked(GUICtrlGetHandle($TreeView), $hItem ,False)         ;--- Change this
62                ;_GUICtrlTreeView_SetChecked(GUICtrlGetHandle($TreeView), $hItem ,True)                 ;--- Change this
63        EndIf
64EndFunc
65;==================================================================================================================
66Func GUIExit()
67        Exit
68EndFunc