#include <GUIEdit.au3>
#include <GuiListView.au3>
#include <Editconstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Global $msg, $hWnd, $hListview, $hEdit, $aHit, $aPos, $hDC, $hBrush,$lable
$hWnd = GUICreate('Listview edit all subitem')
$hListview = _GUICtrlListView_Create($hWnd, '', 6, 6, 708, 370, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListview, $LVS_EX_GRIDLINES)
$lable=GUICtrlCreateLabel("",10,10,10,10)
GUICtrlSetState(-1,$gui_HIDE)
For $i = 0 To 4
_GUICtrlListView_InsertColumn($hListview, 0, 'row' & 4 - $i, 98)
Next
For $i = 0 To 4
_GUICtrlListView_AddItem($hListview, 'item' & $i, $i)
For $j = 1 To 4
_GUICtrlListView_AddSubItem($hListview, $i, 'subitem' & $j, $j)
Next
Next
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState(@SW_SHOW)
Do
Until GUIGetMsg() = -3
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $iCode
Case $NM_DBLCLK
GUICtrlSetState($lable,$gui_HIDE)
$aHit = _GUICtrlListView_SubItemHitTest($hListview)
Local $aRect = _GUICtrlListView_GetSubItemRect($hListview, $aHit[0], $aHit[1])
Local $aPos = ControlGetPos($hWnd, '', $hListview)
Local $text = _GUICtrlListView_GetItemText($hListview, $aHit[0], $aHit[1])
Local $iStyle = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
$hEdit = _GUICtrlEdit_Create($hWnd, $text, $aPos[0] + $aRect[0], $aPos[1] + $aRect[1], _GUICtrlListView_GetColumnWidth($hListview, $aHit[1]), 17, $iStyle)
_GUICtrlEdit_SetSel($hEdit, 0, -1)
_WinAPI_SetFocus($hEdit)
$hDC = _WinAPI_GetWindowDC($hEdit)
$hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
Local $stRect = DllStructCreate('int;int;int;int')
DllStructSetData($stRect, 1, 0)
DllStructSetData($stRect, 2, 0)
DllStructSetData($stRect, 3, _GUICtrlListView_GetColumnWidth($hListview, $aHit[1]))
DllStructSetData($stRect, 4, 17)
_WinAPI_FrameRect($hDC, DllStructGetPtr($stRect), $hBrush)
Case $NM_CLICK
$aHit1 = _GUICtrlListView_SubItemHitTest($hListview)
IF $aHit1[0]<>-1 Then
Local $aRect1 = _GUICtrlListView_GetSubItemRect($hListview, $aHit1[0], $aHit1[1])
Local $aPos1 = ControlGetPos($hWnd, '', $hListview)
Local $text1 = _GUICtrlListView_GetItemText($hListview, $aHit1[0], $aHit1[1])
Local $iStyle1 = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
GUICtrlSetState($lable,$GUI_SHOW)
GUICtrlSetData($lable,$text1)
GUICtrlSetPos($lable,$aPos1[0] + $aRect1[0], $aPos1[1] + $aRect1[1], _GUICtrlListView_GetColumnWidth($hListview, $aHit1[1]),$aRect1[3]-$aRect1[1])
GUICtrlSetBkColor($lable,0x2468a2)
EndIf
EndSwitch
EndFunc ;==>WM_NOTIFY
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local $iCode = BitShift($wParam, 16)
Switch $lParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
Local $iText = _GUICtrlEdit_GetText($hEdit)
_GUICtrlListView_SetItemText($hListview, $aHit[0], $iText, $aHit[1])
_WinAPI_DeleteObject($hBrush)
_WinAPI_ReleaseDC($hEdit, $hDC)
_WinAPI_DestroyWindow($hEdit)
_GUICtrlEdit_Destroy($hEdit)
$Item = -1
$SubItem = 0
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
|