1 | #Include <TreeViewConstants.au3> |
---|
2 | #Include <WindowsConstants.au3> |
---|
3 | #include <GUIConstantsEx.au3> |
---|
4 | #Include <GuiTreeView.au3> |
---|
5 | Opt("GUIOnEventMode", 1) ; Change to OnEvent mode |
---|
6 | Opt("GUICloseOnESC",1) |
---|
7 | |
---|
8 | Global $treeView, $item[10][10] |
---|
9 | GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") |
---|
10 | GUICreate("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 | |
---|
14 | For $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 |
---|
19 | Next |
---|
20 | GUISetOnEvent($GUI_EVENT_CLOSE, "GUIExit") |
---|
21 | GUISetState() |
---|
22 | |
---|
23 | While 1 |
---|
24 | Sleep(100) |
---|
25 | Wend |
---|
26 | |
---|
27 | ;================================================================================================================== |
---|
28 | Func 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 |
---|
49 | EndFunc ;==>WM_Notify_Events |
---|
50 | ;================================================================================================================== |
---|
51 | Func 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 |
---|
64 | EndFunc |
---|
65 | ;================================================================================================================== |
---|
66 | Func GUIExit() |
---|
67 | Exit |
---|
68 | EndFunc |
---|