本帖最后由 水木子 于 2015-8-28 19:13 编辑
回复 1# chzj589
回复 5# cihren
回复 6# away2008
这是我的思路,希望对大家有帮助吧!
顺便卖个关子,留个问题给大家,代码如下,如果被编辑的项目在第一列并且第一列有复选框,怎么才能做得更美观呢?把你的思路(代码)贴上来吧!
#include <WinAPI.au3>
#include <GUIEdit.au3>
#include <WinAPIEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Listview1, $hListview1, $Input1, $hEdit, $aHit, $aRect, $aPos
Global $iHeight = 20
$hWnd = GUICreate('Listview 子项目就地编辑', 600, 450)
$Listview1 = GUICtrlCreateListView('', 5, 5, 590, 430, BitOR($LVS_REPORT, $WS_BORDER), BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
$hListview1 = GUICtrlGetHandle($Listview1)
$hImage = _GUIImageList_Create(1, $iHeight)
_GUICtrlListView_SetImageList($hListview1, $hImage, 1)
For $i = 0 To 4
_GUICtrlListView_InsertColumn($hListview1, $i, 'Row ' & $i, 100)
Next
For $i = 0 To 4
_GUICtrlListView_AddItem($hListview1, 'Item ' & $i, $i)
_GUICtrlListView_AddSubItem($hListview1, $i, 'SubItem ' & 0, 1)
_GUICtrlListView_AddSubItem($hListview1, $i, 'SubItem ' & 1, 2)
_GUICtrlListView_AddSubItem($hListview1, $i, 'SubItem ' & 2, 3)
_GUICtrlListView_AddSubItem($hListview1, $i, 'SubItem ' & 3, 4)
Next
$hFont = _WinAPI_CreateFont($iHeight - 2, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, '微软雅黑')
GUISetState()
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
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
Global $aHit = _GUICtrlListView_SubItemHitTest($hListview1)
If $aHit[0] <> -1 Then
Local $aRect = _GUICtrlListView_GetSubItemRect($hListview1, $aHit[0], $aHit[1])
Local $sItemText = _GUICtrlListView_GetItemText($hListview1, $aHit[0], $aHit[1])
Local $aPos = ControlGetPos($hWnd, '', $hListview1)
Local $iStyle = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
$hEdit = _GUICtrlEdit_Create($hWnd, $sItemText, $aPos[0] + $aRect[0], $aPos[1] + $aRect[1], _GUICtrlListView_GetColumnWidth($hListview1, $aHit[1]), $iHeight, $iStyle)
_WinAPI_BringWindowToTop($hEdit)
_WinAPI_SetFont($hEdit, $hFont, True)
_GUICtrlEdit_SetMargins($hEdit, $EC_LEFTMARGIN, 4)
_WinAPI_SetFocus($hEdit)
_GUICtrlEdit_SetSel($hEdit, 0, -1)
EndIf
Case $NM_CLICK
EndSwitch
EndFunc ;==>WM_NOTIFY
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Local $iCode = BitShift($iwParam, 16)
Local $nMsgID = BitAND($iwParam, 0x0000FFFF)
Switch $ilParam
Case $hEdit
Switch $iCode
Case $EN_KILLFOCUS
_SetItemText()
EndSwitch
EndSwitch
If $nMsgID = 1 And $hEdit <> '' Then
_SetItemText()
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func _SetItemText()
$sItemText = _GUICtrlEdit_GetText($hEdit)
_GUICtrlListView_SetItemText($hListview1, $aHit[0], $sItemText, $aHit[1])
_WinAPI_DestroyWindow($hEdit)
EndFunc ;==>_SetItemText
|