#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Global $hImage, $handlE
Global $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
GUICreate("TreeView", 400, 400)
$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
For $x = 0 To 8
_GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] Новый пункт", $x + 1))
Next
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview, $hItem
$hWndTreeview = $hTreeView
If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
; Case $
; _GUICtrlTreeView_EndEdit($hTreeView)
Case $TVN_KEYDOWN ; двойной клик
Local $tInfo = DllStructCreate($tagNMTVKEYDOWN, $ilParam)
Local $Key = DllStructGetData($tInfo, "VKey")
Switch DllStructGetData($tInfo, "VKey")
Case 0x71; F2
$hItem = _GUICtrlTreeView_GetSelection($hTreeView)
If $hItem <> 0 Then
_GUICtrlTreeView_EditText($hTreeView, $hItem)
$tInfo = DllStructCreate($tagNMTVDISPINFO, $ilParam)
; Return False
Else
MsgBox(0, 'Сообщение', 'Нужно выделить пункт')
EndIf
EndSwitch
Case $NM_DBLCLK ; двойной клик
$hItem = _GUICtrlTreeView_GetSelection($hTreeView)
$handlE = _GUICtrlTreeView_EditText($hTreeView, $hItem)
; Return False
; Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
; $handlE = _GUICtrlTreeView_GetEditControl($hTreeView)
; MsgBox(4160, "Information", "Дескриптор элемента редактирования: " & $handlE)
Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
Local $tInfo = DllStructCreate($tagNMHDR & ";" & $tagTVITEMEX, $ilParam)
If DllStructGetData($tInfo, "Text") <> 0 Then
Local $tBuffer = DllStructCreate("wchar Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
_GUICtrlTreeView_SetText($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView), DllStructGetData($tBuffer, "Text"))
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc