# Function Reference

# _GUICtrlTreeView_ClickItem

Click on a item

#include <GuiTreeView.au3>
_GUICtrlTreeView_ClickItem ( $hWnd, $hItem [, $sButton = "left" [, $bMove = False [, $iClicks = 1 [, $iSpeed = 0]]]] )

## Parameters

$hWnd | Control ID/Handle to the control
$hItem | Handle to the item
$sButton | [optional] Button to click
$bMove | [optional] If True, the mouse will be moved. If False, the mouse does not move.
$iClicks | [optional] Number of clicks
$iSpeed | [optional] Mouse movement speed

## Return Value

Success: | 1.
Failure: | 0 and sets the @error flag to non-zero.

## Example

    #include "Extras\WM_NOTIFY.au3"

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

    Global $g_idTreeView

    Example()

    Func Example()
        GUICreate("TreeView Click Item (v" & @AutoItVersion & ")", 400, 300)

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

        _WM_NOTIFY_Register()

        Local $hImage = _GUIImageList_Create(16, 16, 5, 3)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 110)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 131)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 165)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 168)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 137)
        _GUIImageList_AddIcon($hImage, "shell32.dll", 146)
        _GUICtrlTreeView_SetNormalImageList($g_idTreeView, $hImage)

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

        _GUICtrlTreeView_ClickItem($g_idTreeView, $hItem, "left", False, 2)

        ; 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_idTreeView
        If Not IsHWnd($g_idTreeView) Then $hWndTreeview = GUICtrlGetHandle($g_idTreeView)

        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
                EndSwitch
        EndSwitch
        Return $GUI_RUNDEFMSG
    EndFunc   ;==>WM_NOTIFY