Ticket #318: GUICtrlCreateTreeViewItem.au3

File GUICtrlCreateTreeViewItem.au3, 4.2 KB (added by anonymous, 17 years ago)
Line 
1#include <GUIConstantsEx.au3>
2#include <WindowsConstants.au3>
3#include <TreeViewConstants.au3>
4#include <StaticConstants.au3>
5
6Opt('MustDeclareVars', 1)
7
8Example()
9
10Func Example()
11        Local $treeview, $generalitem, $displayitem, $aboutitem, $compitem
12        Local $useritem, $resitem, $otheritem, $startlabel, $aboutlabel
13        Local $compinfo, $togglebutton, $infobutton, $statebutton, $cancelbutton
14        Local $msg, $item, $text, $hItem
15       
16        GUICreate("My GUI with treeview", 350, 215)
17
18        $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
19        $generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
20        GUICtrlSetColor(-1, 0x0000C0)
21        $displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
22        GUICtrlSetColor(-1, 0x0000C0)
23        $aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
24        $compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
25        $useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
26        $resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
27        $otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)
28        GUICtrlSetTip($otheritem,"other")
29
30        $startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
31        $aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
32        GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "aboutlabel"-text during initialization
33        $compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
34        GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "compinfo"-text during initialization
35
36        GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
37        $togglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
38        $infobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
39        $statebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
40        $cancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)
41
42        GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "General"-item and paint in bold
43        GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))    ; Expand the "Display"-item and paint in bold
44
45        GUISetState()
46        While 1
47                $msg = GUIGetMsg()
48                Select
49                        Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE
50                                ExitLoop
51
52                        Case $msg = $togglebutton   ; Toggle the bold painting
53                                If BitAND(GUICtrlRead($generalitem), $GUI_DEFBUTTON) Then
54                                        GUICtrlSetState($generalitem, 0)
55                                        GUICtrlSetState($displayitem, 0)
56                                Else
57                                        GUICtrlSetState($generalitem, $GUI_DEFBUTTON)
58                                        GUICtrlSetState($displayitem, $GUI_DEFBUTTON)
59                                EndIf
60
61                        Case $msg = $infobutton
62                                $item = GUICtrlRead($treeview)      ; Get the controlID of the current selected treeview item
63                                If $item = 0 Then
64                                        MsgBox(64, "TreeView Demo", "No item currently selected")
65                                Else
66                                        $text = GUICtrlRead($item, 1) ; Get the text of the treeview item
67                                        If $text == "" Then
68                                                MsgBox(16, "Error", "Error while retrieving infos about item")
69                                        Else
70                                                MsgBox(64, "TreeView Demo", "Current item selected is: " & $text)
71                                        EndIf
72                                EndIf
73
74                        Case $msg = $statebutton
75                                $item = GUICtrlRead($treeview)
76                                If $item > 0 Then
77                                        $hItem = GUICtrlGetHandle($item)
78                                        DllCall("user32.dll", "int", "SendMessage", "hwnd", GUICtrlGetHandle($treeview), "int", $TVM_EXPAND, "int", $TVE_TOGGLE, "hwnd", $hItem)
79                                EndIf
80
81                                ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter)
82                        Case $msg = $generalitem
83                                GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel)
84
85                        Case $msg = $aboutitem
86                                GUICtrlSetState($compinfo, $GUI_HIDE)
87                                GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel)
88
89                        Case $msg = $compitem
90                                GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo)
91                EndSelect
92        WEnd
93
94        GUIDelete()
95EndFunc   ;==>Example
96
97Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
98        Local $idx
99
100        For $idx = $hidestart To $hideend
101                GUICtrlSetState($idx, $GUI_HIDE)
102        Next
103        For $idx = $showstart To $showend
104                GUICtrlSetState($idx, $GUI_SHOW)
105        Next
106EndFunc   ;==>GUIChangeItems