#include <GUIListView.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
Global $hGui, $iDummy, $iInput, $iListView, $hListView, $aActive[2]
; ======
$hGui = GUICreate( "Окно", 200, 250, -1, -1 )
$iListView = GUICtrlCreateListView( "Значение|Настройка", 0, 0, 200, 250, Default, BitOr( $LVS_EX_INFOTIP, $LVS_EX_FULLROWSELECT ) )
$hListView = GUICtrlGetHandle( $iListView )
GUICtrlCreateListViewItem( "Заголовок окна|Окно", $iListView )
GUICtrlCreateListViewItem( "Ширина окна|200", $iListView )
GUICtrlCreateListViewItem( "Высота окна|250", $iListView )
$iInput = GUICtrlCreateInput( '', 0, 0, 0, 0 )
GUICtrlSetState( -1, $GUI_HIDE )
$iDummy = GUICtrlCreateDummy()
Local $AccelKeys[1][2] = [["{ENTER}", $iDummy]]
GUISetAccelerators($AccelKeys)
GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )
GUIRegisterMsg( $WM_COMMAND, "WM_COMMAND" )
GUISetState()
; =====
While Sleep( 50 )
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $iDummy
If ControlGetFocus($hGui) = 'Edit1' Then _
_GUICtrlListView_SaveChanges()
EndSwitch
WEnd
Func _GUICtrlListView_EditItem($hWnd, $iIndex, $iSubItem)
If $iIndex < 0 Then _
Return SetError( 1, 0, 0 )
If $iSubItem <> 1 Then _
Return SetError( 1, 0, 0 ) ;Разрешается редактировать только второй столбец
Local $X, $Y, $W, $H, $aPos, $aRect, $Idx, $iSum = 0
For $Idx = 0 To $iSubItem - 1
$iSum += _GUICtrlListView_GetColumnWidth($hWnd, $Idx)
Next
$aRect = _GUICtrlListView_GetItemRect($hWnd, $iIndex)
$aPos = ControlGetPos($hGui, "", $hWnd)
$X = $iSum + $aPos[0] + $aRect[0]
$Y = $aPos[1] + $aRect[1]
$W = _GUICtrlListView_GetColumnWidth($hWnd, $iSubItem)
$H = $aRect[3] - $aRect[1]
GUICtrlSetPos($iInput, $X, $Y, $W, $H)
GUICtrlSetData($iInput, _GUICtrlListView_GetItemText($hWnd, $iIndex, $iSubItem))
GUICtrlSetState($iListView, $GUI_DISABLE)
GUICtrlSetState($iInput, $GUI_SHOW)
GUICtrlSetState($iInput, $GUI_FOCUS)
; ---
$aActive[0] = $iIndex
$aActive[1] = $iSubItem
Return True
EndFunc
Func _GUICtrlListView_SaveChanges()
Local $sText = GUICtrlRead($iInput)
; ---
If $sText = '' Then
MsgBox( 64, '', 'Invalid value!' )
Else
_GUICtrlListView_BeginUpdate( $hListView )
_GUICtrlListView_SetItemText( $hListView, $aActive[0], $sText, $aActive[1] )
_GUICtrlListView_EndUpdate($hListView)
EndIf
GUICtrlSetState($iInput, $GUI_HIDE)
GUICtrlSetState($iListView, $GUI_ENABLE)
Return True
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
Local $hWndFrom, $iCode, $tNMHDR, $tInfo
; ---
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd( DllStructGetData($tNMHDR, "hWndFrom") )
$iCode = DllStructGetData($tNMHDR, "Code")
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_DBLCLK
_GUICtrlListView_EditItem($hWndFrom, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem"))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
Local $iIDFrom, $iCode
; ---
$iCode = BitShift($wParam, 16)
$iIDFrom = BitAND($wParam, 0xFFFF)
Switch $iIDFrom
Case $iInput
Switch $iCode
Case $EN_KILLFOCUS
GUICtrlSetState($iInput, $GUI_HIDE)
GUICtrlSetState($iListView, $GUI_ENABLE)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc