# Function Reference

# _GUICtrlTreeView_Create

Create a TreeView control

#include <GuiTreeView.au3>
_GUICtrlTreeView_Create ( $hWnd, $iX, $iY [, $iWidth = 150 [, $iHeight = 150 [, $iStyle = 0x00000037 [, $iExStyle = 0x00000000]]]] )

## Parameters

$hWnd | Handle to parent or owner window
$iX | Horizontal position of the control
$iY | Vertical position of the control
$iWidth | [optional] Control width
$iHeight | [optional] Control height
$iStyle | [optional] Control style: $TVS_CHECKBOXES - Enables check boxes for items. A check box will be displayed only if an image is associated with the item. When set to this style, the control effectively uses DrawFrameControl to create and set a state image list containing two images. State image 1 is the unchecked box and state image 2 is the checked box. Setting the state image to zero removes the check box. Version 5.80 displays a check box even if no image is associated with the item. $TVS_DISABLEDRAGDROP - Prevents the control from sending $TVN_BEGINDRAG notification messages $TVS_EDITLABELS - Allows the user to edit the item labels $TVS_FULLROWSELECT - Enables full row selection. The entire row of the selected item is highlighted, and clicking anywhere on an item's row causes it to be selected. This style cannot be used in conjunction with the $TVS_HASLINES style. $TVS_HASBUTTONS - Displays plus and minus buttons next to parent items. The user clicks the buttons to expand or collapse a parent item's list of child items. To include buttons with items at the root, you must also specify $TVS_LINESATROOT. $TVS_HASLINES - Uses lines to show the hierarchy of items $TVS_INFOTIP - Obtains ToolTip information by sending the $TVN_GETINFOTIP notification $TVS_LINESATROOT - Uses lines to link items at the root of the control. This value is ignored if $TVS_HASLINES is not also specified. $TVS_NOHSCROLL - Disables horizontal scrolling in the control. The control will not display any horizontal scroll bars. $TVS_NONEVENHEIGHT - Sets the height of the items to an odd height with the $TVM_SETITEMHEIGHT message. By default the height of items must be an even value. $TVS_NOSCROLL - Disables both horizontal and vertical scrolling in the control. The control will not display any scroll bars. $TVS_NOTOOLTIPS - Disables ToolTips $TVS_RTLREADING - Causes text to be displayed from right to left $TVS_SHOWSELALWAYS - Causes a selected item to remain selected when the control loses focus $TVS_SINGLEEXPAND - Causes the item being selected to expand and the item being unselected to collapse upon selection. If the mouse is used to single-click the selected item and that item is closed, it will be expanded. If the user holds down the CTRL key while selecting an item, the item being unselected will not be collapsed. Version 5.80 causes the item being selected to expand and the item being unselected to collapse upon selection. If the user holds down the CTRL key while selecting an item, the item being unselected will not be collapsed. $TVS_TRACKSELECT - Enables hot tracking Default: $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS Forced: $WS_CHILD, $WS_VISIBLE
$iExStyle | [optional] Control extended style

## Return Value

Success: | the handle to the control.
Failure: | 0.

## Remarks

This function is for Advanced users and for learning how the control works.

## Related

_GUICtrlTreeView_Destroy

## Example

### Example : Created with UDF

    #include "Extras\WM_NOTIFY.au3"

    #include <GUIConstantsEx.au3>
    #include <GuiTreeView.au3>
    #include <StructureConstants.au3>
    #include <WindowsNotifsConstants.au3>
    #include <WindowsStylesConstants.au3>

    Global $g_hTreeView

    Example()

    Func Example()
        Local $hGUI = GUICreate("TreeView Create (v" & @AutoItVersion & ")", 400, 300)

        Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
        $g_hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
        GUISetState(@SW_SHOW)

        _WM_NOTIFY_Register()

        _GUICtrlTreeView_BeginUpdate($g_hTreeView)
        Local $hItem
        For $x = 0 To 5
            $hItem = _GUICtrlTreeView_Add($g_hTreeView, 0, StringFormat("[%02d] New Item", $x))
            For $y = 0 To 3
                _GUICtrlTreeView_AddChild($g_hTreeView, $hItem, StringFormat("[%02d] New Child", $y))
            Next
        Next
        _GUICtrlTreeView_EndUpdate($g_hTreeView)

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
    EndFunc   ;==>Example

    Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
        #forceref $hWnd, $iMsg, $wParam
        Local $hWndTreeview = $g_hTreeView
        If Not IsHWnd($g_hTreeView) Then $hWndTreeview = GUICtrlGetHandle($g_hTreeView)

        Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
        Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        Local $iCode = DllStructGetData($tNMHDR, "Code")
        Switch $hWndFrom
            Case $hWndTreeview
                Switch $iCode
                    Case $NM_CLICK ; The user has clicked the left mouse button within the control
                        _WM_NOTIFY_DebugEvent("$NM_CLICK", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                        ; Return 1 ; nonzero to not allow the default processing
                        Return 0 ; zero to allow the default processing
                    Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
                        _WM_NOTIFY_DebugEvent("$NM_DBLCLK", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                        ; Return 1 ; nonzero to not allow the default processing
                        Return 0 ; zero to allow the default processing
                    Case $NM_RCLICK ; The user has clicked the right mouse button within the control
                        _WM_NOTIFY_DebugEvent("$NM_RCLICK", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                        ; Return 1 ; nonzero to not allow the default processing
                        Return 0 ; zero to allow the default processing
                    Case $NM_RDBLCLK ; The user has double-clicked the right mouse button within the control
                        _WM_NOTIFY_DebugEvent("$NM_RDBLCLK", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                        ; Return 1 ; nonzero to not allow the default processing
                        Return 0 ; zero to allow the default processing
                    Case $NM_KILLFOCUS ; control has lost the input focus
                        _WM_NOTIFY_DebugEvent("$NM_KILLFOCUS", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                        ; No return value
                    Case $NM_RETURN ; control has the input focus and that the user has pressed the key
                        _WM_NOTIFY_DebugEvent("$NM_RETURN", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                        ; Return 1 ; nonzero to not allow the default processing
                        Return 0 ; zero to allow the default processing
    ;~              Case $NM_SETCURSOR ; control is setting the cursor in response to a WM_SETCURSOR message
    ;~                  _WM_NOTIFY_DebugEvent("$NM_SETCURSOR", $tagNMMOUSE, $lParam, "IDFrom,,ItemSpec,ItemData,X,Y,HitInfo")
    ;~                  Return 0 ; to enable the control to set the cursor
    ;~                  ; Return 1 ; nonzero to prevent the control from setting the cursor
                    Case $NM_SETFOCUS ; control has received the input focus
                        _WM_NOTIFY_DebugEvent("$NM_SETFOCUS", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                        ; No return value
                    Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
                        _WM_NOTIFY_DebugEvent("$TVN_BEGINDRAG", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
                        _WM_NOTIFY_DebugEvent("$TVN_BEGINLABELEDIT", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_BEGINRDRAGA, $TVN_BEGINRDRAGW
                        _WM_NOTIFY_DebugEvent("$TVN_BEGINRDRAG", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_DELETEITEMA, $TVN_DELETEITEMW
                        _WM_NOTIFY_DebugEvent("$TVN_DELETEITEM", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
                        _WM_NOTIFY_DebugEvent("$TVN_ENDLABELEDIT", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_GETDISPINFOA, $TVN_GETDISPINFOW
                        _WM_NOTIFY_DebugEvent("$TVN_GETDISPINFO", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_GETINFOTIPA, $TVN_GETINFOTIPW
                        _WM_NOTIFY_DebugEvent("$TVN_GETINFOTIP", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
                        _WM_NOTIFY_DebugEvent("$TVN_ITEMEXPANDED", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
                        _WM_NOTIFY_DebugEvent("$TVN_ITEMEXPANDING", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_KEYDOWN
                        _WM_NOTIFY_DebugEvent("$TVN_KEYDOWN", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                        _WM_NOTIFY_DebugEvent("$TVN_SELCHANGED", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW
                        _WM_NOTIFY_DebugEvent("$TVN_SELCHANGING", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_SETDISPINFOA, $TVN_SETDISPINFOW
                        _WM_NOTIFY_DebugEvent("$TVN_SETDISPINFO", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                    Case $TVN_SINGLEEXPAND
                        _WM_NOTIFY_DebugEvent("$TVN_SINGLEEXPAND", $tagNMHDR, $lParam, "hWndFrom,IDFrom")
                EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
    EndFunc   ;==>WM_NOTIFY