#include <GUIConstantsEx.au3>
#include <GUITreeView.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("TreeView, редактирование пункта", 400, 300)

$iTreeView = GUICtrlCreateTreeView(10, 10, 380, 240, BitOR($TVS_EDITLABELS, $TVS_DISABLEDRAGDROP), $WS_EX_CLIENTEDGE)

For $i = 1 To 10
	GUICtrlCreateTreeViewItem('Пункт ' & $i, $iTreeView)
Next

$iRename_Bttn = GUICtrlCreateButton('Переименовать', 10, 265, 110, 25)

$iESC_Dummy = GUICtrlCreateDummy()
$iEnter_Dummy = GUICtrlCreateDummy()

Dim $aAccelKeys[2][2] = [['{ESC}', $iESC_Dummy], ['{ENTER}', $iEnter_Dummy]]
GUISetAccelerators($aAccelKeys)

GUISetState()

While 1
	$nMsg = GUIGetMsg()

	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $iRename_Bttn
			$hItem = _GUICtrlTreeView_GetSelection($iTreeView)
			_GUICtrlTreeView_EditText($iTreeView, $hItem)
		Case $iESC_Dummy
			_GUICtrlTreeView_EndEdit($iTreeView, True)
		Case $iEnter_Dummy
			$hItem = _GUICtrlTreeView_GetSelection($iTreeView)
			$hEdit = _GUICtrlTreeView_GetEditControl($iTreeView)

			_GUICtrlTreeView_SetText($iTreeView, $hItem, ControlGetText($hGUI, '', $hEdit))
			_GUICtrlTreeView_EndEdit($iTreeView, False)
	EndSwitch
WEnd