#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Global $hGTVE, $hModificationItemTV, $sNewTxtItemTV, $nFlag, $iNotEdit
Global $Form1 = GUICreate("Form1", 390, 426, 619, 180)
Global $TreeView1 = GUICtrlCreateTreeView(40, 8, 313, 385, BitOR($TVS_HASBUTTONS, $TVS_EDITLABELS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS))
Local $aHItem[0][2], $idItem, $iMap
For $i = 0 To 20
$idItem = GUICtrlCreateTreeViewItem($i, $TreeView1)
If $i = 10 Then
$iMap = 1;редактировать запрещено
Else
$iMap = 0
EndIf
_ArrayAdd($aHItem, GUICtrlGetHandle($idItem) & '|' & $iMap)
Next
GUISetState()
GUIRegisterMsg($WM_NOTIFY, '_GUITreeViewEx')
Local $nMsg
While 1
If $nFlag Then
$iNotEdit = 0
For $i = 0 To UBound($aHItem) - 1
If $aHItem[$i][0] = $hModificationItemTV Then
$nFlag = 0
If $aHItem[$i][1] = 0 Then
_GUICtrlTreeView_EditText($hGTVE, $hModificationItemTV)
Else
$iNotEdit = 1
;~ MsgBox(0, '', 'Запрет на редактирование', 0, $Form1)
EndIf
EndIf
Next
EndIf
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _GUITreeViewEx($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hItem, $nAction, $aInfTv
Local $tStruct = DllStructCreate('struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;' & _
'uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;' & _
'ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;' & _
'struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;' & _
'ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;' & _
'struct;long PointX;long PointY;endstruct', $lParam)
Local $hWndFrom = DllStructGetData($tStruct, 'hWndFrom')
$hGTVE = $hWndFrom
Switch DllStructGetData($tStruct, 'Code')
Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
$hItem = DllStructGetData($tStruct, 'NewhItem')
If $hItem Then $hModificationItemTV = $hItem
Case $NM_DBLCLK
$nFlag = 1
;~ _GUICtrlTreeView_EditText($hGTVE, $hModificationItemTV)
Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
If Not $iNotEdit Then
Local $tInfo = DllStructCreate($tagNMHDR & ';' & $tagTVITEMEX, $lParam)
If DllStructGetData($tInfo, 'Text') <> 0 Then
Local $tBuffer = DllStructCreate('wchar Text[' & DllStructGetData($tInfo, 'TextMax') & ']', DllStructGetData($tInfo, 'Text'))
If StringStripWS(DllStructGetData($tBuffer, 'Text'), 3) Then
$sNewTxtItemTV = StringReplace(StringRegExpReplace(DllStructGetData($tBuffer, 'Text'), '[*~|#]', ' '), '\', '')
_GUICtrlTreeView_SetText($hGTVE, $hModificationItemTV, $sNewTxtItemTV)
_GUICtrlTreeView_EndEdit($hGTVE)
EndIf
EndIf
EndIf
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_GUITreeViewEx