习惯了使用EXCEL表格输入数据时候回车自动到下一行,使用ListViewEditEvent这个UDF只有双击后才能显示EDIT输入框,感觉不方便。
看了以下源码,奈何能力不够看了一圈还是没有一个所以然,尝试着修改了一下,没有成功。
奉上代码,希望寻得帮助!!!
想要实现的功能:
1、双击LISTVIEW某一行的SubItem后出现EDIT编辑框
2、输入数据后回车,保存数据,并在下一行的同列SubItem出现EDIT编辑框
3、以此例推,到LISTVIEW的最后一行SubItem后出现EDIT编辑框后输入数据,回车后只保存数据,不再出现EDIT编辑框
我自己添加的代码在__ListViewEditDefProcedure这个function的$f_ListViewEditMsgIsSending = 0后面
;=====================================添加的部分=============================================
Local $iMax= _GUICtrlListView_GetItemCount($iListView)
Local $aIndices = _GUICtrlListView_GetSelectedIndices($iListView , 1)
If $aIndices[1]<$iMax-1 Then
_GUICtrlListView_SetItemSelected($iListView, $aIndices[1]+1)
_GUICtrlListView_EditItem($iListView , $aIndices[1]+1, 2)
EndIf
;================================添加的部分=============================================
按下了回车键后可以实现我想要的功能,但是数据输入到最后一行后,按下向上的按键就不是从最后一行开始了。
这个问题该怎么解决??
如果我要实现向EXCEL中那样,回车后直接到下一行EDIT编辑框,按向下或者向上按键,编辑框随按键向上或者向下运动,向上到第一行或者向下到最后一行后编辑框消失。要实现这样的效果该怎么做??
例子:
#include <GUIStatusBar.au3>
#include <ListViewEditEvent.au3>
; 下例中,Item 0 ~ Item 8 及其子条目可进行编辑操作,Item 9 及子条目不能。
; Item 9的CheckBox只能为非选中状态,其他只能用鼠标左键点选。
; 只能用鼠标左右键进行选择,拒绝上下箭头选择。
; 只能输入enter键以保存编辑结果,其他均不保存。
$hGUI = GUICreate("Test - ListViewEditEvent", 400, 300)
$iStyle = bitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $WS_EX_CLIENTEDGE)
$iListView = GUICtrlCreateListView("Col 1|Col 2|Col 3", 5, 5, 390, 270)
$hListView = GUICtrlGetHandle(-1)
_GUICtrlListView_SetExtendedListViewStyle($hListView, $iStyle)
For $i = 1 To 10
_GUICtrlListView_AddItem($hListView, "Item " & ($i))
_GUICtrlListView_AddSubItem($hListView, ($i - 1), ("Item " & ($i) & " - 1"), 1)
_GUICtrlListView_AddSubItem($hListView, ($i - 1), ("Item " & ($i) & " - 2"), 2)
Next
_GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE)
_GUICtrlListView_RegisterEditEvent($hListView) ; 为ListView注册Edit消息。
; 原型 - _GUICtrlListView_RegisterEditEvent($hListView, $fAutoComplete = 1)
; $hListView - ListView控件句柄。
; $fAutoComplete - 如果设为1,即使用户不处理LVN_EDITEND通知,ListView同样自动保存结果。反之则不保存。
Local $aPart[3] = [150, 300, -1]
$hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aPart)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Do
Until GUIGetMsg() = -3
Opt("TrayIconHide", 1)
ProcessClose(@AutoItPid)
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tBuffer, $iCode, $iItem, $iSubItem
$tBuffer = DllStructCreate($tagNMLISTVIEWHDR, $ilParam)
$iCode = DllStructGetData($tBuffer, "Code")
Switch $iCode
Case $LVN_EDITBEGIN ; 将要开始编辑。
Case $LVN_EDITEND ; 结束编辑。
EndSwitch
$tBuffer = 0
EndFunc ;==>WM_NOTIFY
ListViewEditEvent.au3
#include <WinAPI.au3>
#include <Array.au3>
#include <GUIListView.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
; #### Variables for ListView edit notifications ####
; ===============================================================================================
Global $a_ListViewEditControls[1][4] = [[0]]
Global $h_ListViewEditDefProcedure = DllCallbackRegister("__ListViewEditDefProcedure", "int", "hWnd;uint;wparam;lparam")
Global $p_ListViewEditDefProcedure = DllCallbackGetPtr($h_ListViewEditDefProcedure)
Global $h_ListViewEditDefCall
Global $i_ListViewEditItem
Global $i_ListViewEditSubItem
Global $i_ListViewEditCounter
Global $f_ListViewMsgIsSending
Global $f_ListViewEditMsgIsSending
Global $h_ListViewDefProcedure = DllCallbackRegister("__ListViewDefProcedureeee", "int", "hWnd;uint;wparam;lparam")
Global $p_ListViewDefProcedure = DllCallbackGetPtr($h_ListViewDefProcedure)
Global $h_ListViewDefCall
; ===============================================================================================
; #### Structures for ListView edit notifications ####
; ===============================================================================================
Const $tagNMLISTVIEWHDR = "hWnd hWndFrom;int IDFrom;int Code"
Const $tagLISTVIEW_EDITBEGIN = $tagNMLISTVIEWHDR & ";int Item;int SubItem;int Show"
Const $tagLISTVIEW_EDITEND = $tagNMLISTVIEWHDR & ";int Item;int SubItem;int EndFlags;dword Length;ptr Text;int AutoComplete"
Const $tagLISTVIEW_SELCHANGING = $tagNMLISTVIEWHDR & ";int CurrentItem;int NewItem;dword ChangeFlags;int AllowChange"
Const $tagLISTVIEW_SELCHANGED = $tagNMLISTVIEWHDR & ";int PreviousItem;int CurrentItem;dword ChangeFlags;int Reserved"
Const $tagLISTVIEW_ITEMCHECKING = $tagNMLISTVIEWHDR & ";int Item;int CurrentChecked;int NewChecked;int Flags;int AllowCheck"
Const $tagLISTVIEW_ITEMCHECKED = $tagNMLISTVIEWHDR & ";int Item;int CurrentChecked;int PreviousChecked;int Flags"
; ===============================================================================================
; #### Flags for LISTVIEW_SELCHANGING.ChangeFlags ####
; ===============================================================================================
Const $LVCF_UPARROW = 1
Const $LVCF_DOWNARROW = 2
Const $LVCF_LBUTTON = 3
Const $LVCF_RBUTTON = 4
Const $LVCF_INTERNAL = 5
Const $LVCF_SPACE = 6
; ===============================================================================================
; #### Flags for LISTVIEW_ITEMCHECKING.Flags ####
; ===============================================================================================
Const $LVICF_SPACE = 1
Const $LVICF_LBUTTON = 2
Const $LVICF_RBUTTON = 3
Const $LVICF_INTERNAL = 4
Const $LVICF_EXTERNAL = 5
; ===============================================================================================
; #### Notifications for ListView ####
; ===============================================================================================
Const $LVN_EDITBEGIN = $LVN_FIRST - 777
Const $LVN_EDITEND = $LVN_FIRST - 7777
Const $LVN_SELCHANGING = $LVN_FIRST - 77777
Const $LVN_SELCHANGED = $LVN_FIRST - 777777
Const $LVN_ITEMCHECKING = $LVN_FIRST - 7777777
Const $LVN_ITEMCHECKED = $LVN_FIRST - 77777777
; ===============================================================================================
; #### Flags for LISTVIEW_EDIT.EndFlags ####
; ===============================================================================================
Const $LVEF_ENTER = 1
Const $LVEF_ESC = 2
Const $LVEF_LOSEFOCUS = 3
Const $LVEF_CANCEL = 4
Const $LVEF_FORCECLOSE = 5
; ===============================================================================================
; #### Default procedure for ListView controls ####
; ===============================================================================================
Func __ListViewDefProcedureeee($hWnd, $iMsg, $iwParam, $ilParam)
Switch $iMsg
Case $WM_VSCROLL, $WM_HSCROLL
Local $iEditId = _GUICtrlListView_GetEditId($hWnd)
If BitAND(GUICtrlGetState($iEditId), $GUI_SHOW) Then Return 1
Case $LVM_HITTEST
Local $tBuffer, $iListView, $hParent, $iItem, $iFlags, $fChecked, $vDefReturn
$vDefReturn = _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
$tBuffer = DllStructCreate("long X;long Y;uint Flags;int Item;int SubItem", $ilParam)
If (DllStructGetData($tBuffer, "Flags") <> 8) Then
$tBuffer = 0
Return $vDefReturn
EndIf
$iItem = DllStructGetData($tBuffer, "Item")
$fChecked = _GUICtrlListView_GetItemChecked($hWnd, $iItem)
$tBuffer = 0
$iListView = _WinAPI_GetDlgCtrlID($hWnd)
$hParent = _WinAPI_GetParent($hWnd)
$tBuffer = DllStructCreate($tagLISTVIEW_ITEMCHECKING)
DllStructSetData($tBuffer, "hWndFrom", $hWnd)
DllStructSetData($tBuffer, "IDFrom", $iListView)
DllStructSetData($tBuffer, "Code", $LVN_ITEMCHECKING)
DllStructSetData($tBuffer, "Item", $iItem)
DllStructSetData($tBuffer, "CurrentChecked", $fChecked)
DllStructSetData($tBuffer, "NewChecked", Not $fChecked)
DllStructSetData($tBuffer, "AllowCheck", 1)
$iFlags = DllCall("User32.dll", "short", "GetAsyncKeyState", "int", 1)
If BitAND($iFlags[0], 0x8000) Then
DllStructSetData($tBuffer, "Flags", $LVICF_LBUTTON)
Else
$iFlags = DllCall("User32.dll", "short", "GetAsyncKeyState", "int", 2)
If BitAND($iFlags[0], 0x8000) Then
DllStructSetData($tBuffer, "Flags", $LVICF_RBUTTON)
Else
DllStructSetData($tBuffer, "Flags", $LVICF_EXTERNAL)
EndIf
EndIf
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, DllStructGetPtr($tBuffer))
If (DllStructGetData($tBuffer, "AllowCheck") = 0) Then
$tBuffer = 0
_GUICtrlListView_SetItemChecked($hWnd, $iItem, Not $fChecked)
Return 1
EndIf
$iFlags = DllStructGetData($tBuffer, "Flags")
$tBuffer = 0
$vDefReturn = _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
$tBuffer = DllStructCreate($tagLISTVIEW_ITEMCHECKED)
DllStructSetData($tBuffer, "hWndFrom", $hWnd)
DllStructSetData($tBuffer, "IDFrom", $iListView)
DllStructSetData($tBuffer, "Code", $LVN_ITEMCHECKED)
DllStructSetData($tBuffer, "Item", $iItem)
DllStructSetData($tBuffer, "CurrentChecked", Not $fChecked)
DllStructSetData($tBuffer, "PreviousChecked", $fChecked)
DllStructSetData($tBuffer, "Flags", $iFlags)
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, DllStructGetPtr($tBuffer))
$tBuffer = 0
Return $vDefReturn
Case $WM_NOTIFY
Local $tBuffer, $iCode, $iEditId, $iCol
$tBuffer = DllStructCreate($tagNMHDR & ";int Column", $ilParam)
$iCode = DllStructGetData($tBuffer, "Code")
$iCol = DllStructGetData($tBuffer, "Column")
$tBuffer = 0
If ($iCode = -328) Or ($iCode = -308) Then
If ($iCol = $i_ListViewEditSubItem) Or ($iCol = ($i_ListViewEditSubItem - 1)) Then
$iEditId = _GUICtrlListView_GetEditId($hWnd)
If BitAND(GUICtrlGetState($iEditId), $GUI_SHOW) Then Return 1
EndIf
EndIf
Case $WM_LBUTTONDBLCLK
Local $iX, $iY, $aInfo, $tBuffer, $pBuffer, $iListView
$iX = BitAND($ilParam, 0xFFFF)
$iY = BitShift($ilParam, 0x10)
$aInfo = _GUICtrlListView_SubItemHitTest($hWnd, $iX, $iY)
; _Arraydisplay($aInfo)
If (Not $aInfo[2]) And (Not $aInfo[3]) And (Not $aInfo[4]) _
And ($aInfo[5]) And ($aInfo[6]) And ($aInfo[7]) _
And (Not $aInfo[8]) And (Not $aInfo[9]) And (Not $aInfo[10]) Then
Return 1
EndIf
If ($aInfo[0] <> -1) Then
$iListView = _WinAPI_GetDlgCtrlID($hWnd)
$tBuffer = DllStructCreate($tagLISTVIEW_EDITBEGIN)
$pBuffer = DllStructGetPtr($tBuffer)
DllStructSetData($tBuffer, "hWndFrom", $hWnd)
DllStructSetData($tBuffer, "IDFrom", $iListView)
DllStructSetData($tBuffer, "Code", $LVN_EDITBEGIN)
DllStructSetData($tBuffer, "Item", $aInfo[0])
DllStructSetData($tBuffer, "SubItem", $aInfo[1])
DllStructSetData($tBuffer, "Show", 1)
_WinAPI_PostMessage(_WinAPI_GetParent($hWnd), $WM_NOTIFY, $iListView, $pBuffer)
If (DllStructGetData($tBuffer, "Show") <> 0) Then
_GUICtrlListView_EditItem($hWnd, $aInfo[0], $aInfo[1])
EndIf
$tBuffer = 0
EndIf
$aInfo = 0
Case $WM_RBUTTONDOWN, $WM_LBUTTONDOWN, $WM_KEYDOWN
_WinAPI_SetFocus($hWnd)
Local $aIndices, $iItem = -1, $iNewItem = -1, $iX, $iY, $tXY, $aInfo, $tBuffer, $iListView
If ($iMsg = $WM_KEYDOWN) And ($iwParam = 32) Then
Local $aIndices = _GUICtrlListView_GetSelectedIndices($hWnd, 1)
If ($aIndices[0] = 0) Then
For $i = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1
If _GUICtrlListView_GetItemFocused($hWnd, $i) = 0 Then ContinueLoop
$iItem = $i
ExitLoop
Next
Else
$iItem = $aIndices[1]
EndIf
$aIndices = 0
If ($iItem = -1) Then
Return _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
$iListView = _WinAPI_GetDlgCtrlID($hWnd)
$hParent = _WinAPI_GetParent($hWnd)
Local $fChecked = _GUICtrlListView_GetItemChecked($hWnd, $iItem)
$tBuffer = DllStructCreate($tagLISTVIEW_ITEMCHECKING)
DllStructSetData($tBuffer, "hWndFrom", $hWnd)
DllStructSetData($tBuffer, "IDFrom", $iListView)
DllStructSetData($tBuffer, "Code", $LVN_ITEMCHECKING)
DllStructSetData($tBuffer, "Item", $iItem)
DllStructSetData($tBuffer, "CurrentChecked", $fChecked)
DllStructSetData($tBuffer, "NewChecked", Not $fChecked)
DllStructSetData($tBuffer, "Flags", $LVICF_SPACE)
DllStructSetData($tBuffer, "AllowCheck", 1)
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, DllStructGetPtr($tBuffer))
If (DllStructGetData($tBuffer, "AllowCheck") = 0) Then
$tBuffer = 0
Return 1
EndIf
$tBuffer = 0
Local $vDefReturn
$vDefReturn = _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
$tBuffer = DllStructCreate($tagLISTVIEW_ITEMCHECKED)
DllStructSetData($tBuffer, "hWndFrom", $hWnd)
DllStructSetData($tBuffer, "IDFrom", $iListView)
DllStructSetData($tBuffer, "Code", $LVN_ITEMCHECKED)
DllStructSetData($tBuffer, "Item", $iItem)
DllStructSetData($tBuffer, "Flags", $LVICF_SPACE)
DllStructSetData($tBuffer, "CurrentChecked", Not $fChecked)
DllStructSetData($tBuffer, "PreviousChecked", $fChecked)
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, DllStructGetPtr($tBuffer))
$tBuffer = 0
Return $vDefReturn
EndIf
If ($iMsg = $WM_KEYDOWN) And (($iwParam <> 38) And ($iwParam <> 40)) Then
Return _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
$aIndices = _GUICtrlListView_GetSelectedIndices($hWnd, True)
If ($aIndices[0] <> 0) And ($iMsg = $WM_KEYDOWN) Then
If ($iwParam = 38) Then
$iItem = $aIndices[1]
$iNewItem = $iItem - 1
Else
$iItem = $aIndices[$aIndices[0]]
$iNewItem = $iItem + 1
EndIf
ElseIf ($aIndices[0] = 0) Then
For $i = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1
If (_GUICtrlListView_GetItemFocused($hWnd, $i) = 0) Then ContinueLoop
$iItem = $i
ExitLoop
Next
If ($iItem = -1) Then
Return _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
ElseIf ($iMsg = $WM_KEYDOWN) Then
If ($iwParam = 38) Then
$iNewItem = $iItem - 1
Else
$iNewItem = $iItem + 1
EndIf
EndIf
EndIf
If ($iMsg = $WM_LBUTTONDOWN) Or ($iMsg = $WM_RBUTTONDOWN) Then
$iX = BitAND($ilParam, 0xFFFF)
$iY = BitShift($ilParam, 0x10)
Local $fOnCbx = _GUICtrlListView_PointIsHoverCheckBox($hWnd, $iX, $iY)
If ($fOnCbx) Then
$iItem = _GUICtrlListView_GetSelectedIndices($hWnd, 1)
If ($iItem[0] = 0) Then
$iItem = -1
Else
$iItem = $iItem[1]
EndIf
$iNewItem = $iItem
Else
$aInfo = _GUICtrlListView_SubItemHitTest($hWnd, $iX, $iY)
If ($aIndices[0] = 0) Then
$iItem = -1
Else
$iItem = $aIndices[1]
EndIf
$iNewItem = $aInfo[0]
EndIf
EndIf
If ($iNewItem = $iItem) Then
Return _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
If (($iMsg = $WM_LBUTTONDOWN) Or ($iMsg = $WM_RBUTTONDOWN)) And ($iItem <> $iNewItem) Then
$tBuffer = DllStructCreate($tagLISTVIEW_SELCHANGING)
$iListView = _WinAPI_GetDlgCtrlID($hWnd)
DllStructSetData($tBuffer, "hWndFrom", $hWnd)
DllStructSetData($tBuffer, "IDFrom", $iListView)
DllStructSetData($tBuffer, "Code", $LVN_SELCHANGING)
DllStructSetData($tBuffer, "CurrentItem", $iItem)
DllStructSetData($tBuffer, "NewItem", $iNewItem)
DllStructSetData($tBuffer, "AllowChange", 1)
If ($iMsg = $WM_LBUTTONDOWN) Then
DllStructSetData($tBuffer, "ChangeFlags", $LVCF_LBUTTON)
Else
DllStructSetData($tBuffer, "ChangeFlags", $LVCF_RBUTTON)
EndIf
Local $pBuffer = DllStructGetPtr($tBuffer)
Local $hParent = _WinAPI_GetParent($hWnd)
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, $pBuffer)
If DllStructGetData($tBuffer, "AllowChange") = 0 Then
$tBuffer = 0
Return 1
EndIf
Local $vDefReturn, $tChanged
$vDefReturn = _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
$tChanged = DllStructCreate($tagLISTVIEW_SELCHANGED)
DllStructSetData($tChanged, "hWndFrom", $hWnd)
DllStructSetData($tChanged, "IDFrom", $iListView)
DllStructSetData($tChanged, "Code", $LVN_SELCHANGED)
DllStructSetData($tChanged, "PreviousItem", $iItem)
DllStructSetData($tChanged, "CurrentItem", $iNewItem)
DllStructSetData($tChanged, "ChangeFlags", DllStructGetData($tBuffer, "ChangeFlags"))
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, DllStructGetPtr($tChanged))
$tBuffer = 0
$tChanged = 0
Return $vDefReturn
EndIf
If ($iwParam = 38) Then
If ($iNewItem < 0) Then $iNewItem = 0
Else
Local $iMax = _GUICtrlListView_GetItemCount($hWnd)
If ($iNewItem >= $iMax) Then $iNewItem = $iMax - 1
EndIf
If ($iNewItem = $iItem) Then
Return _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
$tBuffer = DllStructCreate($tagLISTVIEW_SELCHANGING)
$iListView = _WinAPI_GetDlgCtrlID($hWnd)
DllStructSetData($tBuffer, "hWndFrom", $hWnd)
DllStructSetData($tBuffer, "IDFrom", $iListView)
DllStructSetData($tBuffer, "Code", $LVN_SELCHANGING)
DllStructSetData($tBuffer, "CurrentItem", $iItem)
DllStructSetData($tBuffer, "NewItem", $iNewItem)
DllStructSetData($tBuffer, "AllowChange", 1)
If ($iwParam = 38) Then
DllStructSetData($tBuffer, "ChangeFlags", $LVCF_UPARROW)
Else
DllStructSetData($tBuffer, "ChangeFlags", $LVCF_DOWNARROW)
EndIf
Local $pBuffer = DllStructGetPtr($tBuffer)
_WinAPI_PostMessage(_WinAPI_GetParent($hWnd), $WM_NOTIFY, $iListView, $pBuffer)
If DllStructGetData($tBuffer, "AllowChange") = 0 Then
$tBuffer = 0
Return 1
EndIf
$tBuffer = 0
Case $LVM_SETITEMSTATE
Local $tBuffer, $iMask, $iState, $iItem, $iNewItem, $tChange, $iListView, $hParent
$tBuffer = DllStructCreate($tagLVITEM, $ilParam)
$iMask = DllStructGetData($tBuffer, "Mask")
If BitAND($iMask, $LVIF_STATE) <> $LVIF_STATE Then
$tBuffer = 0
Return _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
$iState = DllStructGetData($tBuffer, "State")
If BitAND($iState, $LVIS_SELECTED) <> $LVIS_SELECTED Then
$tBuffer = 0
Return _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
$iNewItem = DllStructGetData($tBuffer, "Item")
$iItem = _GUICtrlListView_GetSelectedIndices($hWnd, 1)
If ($iItem[0] = 0) Then
$iItem = -1
Else
$iItem = $iItem[1]
EndIf
$tBuffer = 0
If ($iNewItem = $iItem) Then
Return _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
$iListView = _WinAPI_GetDlgCtrlID($hWnd)
$hParent = _WinAPI_GetParent($hWnd)
$tChange = DllStructCreate($tagLISTVIEW_SELCHANGING)
DllStructSetData($tChange, "hWndFrom", $hWnd)
DllStructSetData($tChange, "IDFrom", $iListView)
DllStructSetData($tChange, "Code", $LVN_SELCHANGING)
DllStructSetData($tChange, "CurrentItem", $iItem)
DllStructSetData($tChange, "NewItem", $iNewItem)
DllStructSetData($tChange, "ChangeFlags", $LVCF_INTERNAL)
DllStructSetData($tChange, "AllowChange", 1)
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, DllStructGetPtr($tChange))
If (DllStructGetData($tChange, "AllowChange") = 0) Then
$tChange = 0
Return 1
EndIf
$tChange = 0
Local $vDefReturn
$vDefReturn = _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
$tChange = DllStructCreate($tagLISTVIEW_SELCHANGED)
DllStructSetData($tChange, "hWndFrom", $hWnd)
DllStructSetData($tChange, "IDFrom", $iListView)
DllStructSetData($tChange, "Code", $LVN_SELCHANGED)
DllStructSetData($tChange, "PreviousItem", $iItem)
DllStructSetData($tChange, "CurrentItem", $iNewItem)
DllStructSetData($tChange, "ChangeFlags", $LVCF_INTERNAL)
DllStructSetData($tChange, "Reserved", 0)
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, DllStructGetPtr($tChange))
$tChange = 0
Return $vDefReturn
EndSwitch
Return _WinAPI_CallWindowProc($h_ListViewDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc ;==>__ListViewDefProcedureeee
Func _GUICtrlListView_PointIsHoverCheckbox($hListView, $iX, $iY)
Local $aInfo, $fHover = 0
If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)
$aInfo = _GUICtrlListView_SubItemHitTest($hListView, $iX, $iY)
If (Not $aInfo[2]) And (Not $aInfo[3]) And (Not $aInfo[4]) _
And ($aInfo[5]) And ($aInfo[6]) And ($aInfo[7]) _
And (Not $aInfo[8]) And (Not $aInfo[9]) And (Not $aInfo[10]) Then
$fHover = 1
EndIf
$aInfo = 0
Return $fHover
EndFunc ;==>_GUICtrlListView_PointIsHoverCheckbox
; #### Default procedure for ListView Edit controls ####
; ===============================================================================================
Func __ListViewEditDefProcedure($hWnd, $iMsg, $iwParam, $ilParam)
If ($f_ListViewEditMsgIsSending = 1) Then
Return _WinAPI_CallWindowProc($h_ListViewEditDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
If ($iMsg <> $WM_KILLFOCUS) And ($iMsg <> $WM_KEYUP) And ($iMsg <> $WM_DESTROY) Then
Return _WinAPI_CallWindowProc($h_ListViewEditDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
If ($iMsg = $WM_DESTROY) Then $iwParam = 27
If ($iMsg = $WM_KILLFOCUS) Then $iwParam = 13
If ($iwParam <> 13) And ($iwParam <> 27) Then
Return _WinAPI_CallWindowProc($h_ListViewEditDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
Local $tBuffer, $pBuffer, $hParent, $hListView, $iLength
Local $pText, $tText, $sText, $iListView, $iIndex, $aLVE
$hListView = _WinAPI_GetParent($hWnd)
$iIndex = _GUICtrlListView_GetEditArrayIndex($hListView)
If ($iIndex = 0) Then
Return _WinAPI_CallWindowProc($h_ListViewEditDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndIf
$iListView = _WinAPI_GetDlgCtrlID($hListView)
$hParent = _WinAPI_GetParent($hListView)
$aLVE = $a_ListViewEditControls
$sText = GUICtrlRead($a_ListViewEditControls[$iIndex][1])
$iLength = StringLen($sText) + 2
$tText = DllStructCreate("wchar Text[" & $iLength & "]")
$pText = DllStructGetPtr($tText)
$tBuffer = DllStructCreate($tagLISTVIEW_EDITEND)
$pBuffer = DllStructGetPtr($tBuffer)
DllStructSetData($tText, "Text", $sText)
DllStructSetData($tBuffer, "hWndFrom", $hListView)
DllStructSetData($tBuffer, "IDFrom", $iListView)
DllStructSetData($tBuffer, "Code", $LVN_EDITEND)
DllStructSetData($tBuffer, "Item", $i_ListViewEditItem)
DllStructSetData($tBuffer, "SubItem", $i_ListViewEditSubItem)
DllStructSetData($tBuffer, "Length", DllStructGetSize($tText))
DllStructSetData($tBuffer, "Text", $pText)
DllStructSetData($tBuffer, "AutoComplete", $a_ListViewEditControls[$iIndex][3])
Select
Case $iMsg = $WM_KILLFOCUS
DllStructSetData($tBuffer, "EndFlags", $LVEF_LOSEFOCUS)
Case $iMsg = $WM_DESTROY
DllStructSetData($tBuffer, "EndFlags", $LVEF_FORCECLOSE)
Case $iwParam = 13
DllStructSetData($tBuffer, "EndFlags", $LVEF_ENTER)
Case $iwParam = 27
DllStructSetData($tBuffer, "EndFlags", $LVEF_ESC)
EndSelect
$f_ListViewEditMsgIsSending = 1
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, $pBuffer)
If (DllStructGetData($tBuffer, "AutoComplete") <> 0) Then
Local $tTextReturn
$iLength = DllStructGetData($tBuffer, "Length")
$pText = DllStructGetData($tBuffer, "Text")
$tTextReturn = DllStructCreate("wchar Text[" & ($iLength / 2) & "]", $pText)
$sText = DllStructGetData($tTextReturn, "Text")
$tTextReturn = 0
_GUICtrlListView_SetItemText($hListView, $i_ListViewEditItem, $sText, $i_ListViewEditSubItem)
EndIf
GUICtrlSetState($iListView, $GUI_FOCUS)
GUICtrlSetState($a_ListViewEditControls[$iIndex][1], $GUI_HIDE)
$f_ListViewEditMsgIsSending = 0
;=====================================添加的部分=============================================
Local $iMax= _GUICtrlListView_GetItemCount($iListView)
Local $aIndices = _GUICtrlListView_GetSelectedIndices($iListView , 1)
If $aIndices[1]<$iMax-1 Then
_GUICtrlListView_SetItemSelected($iListView, $aIndices[1]+1)
_GUICtrlListView_EditItem($iListView , $aIndices[1]+1, 2)
EndIf
;================================添加的部分=============================================
$aLVE = 0
$tText = 0
$tBuffer = 0
Return _WinAPI_CallWindowProc($h_ListViewEditDefCall, $hWnd, $iMsg, $iwParam, $ilParam)
EndFunc ;==>__ListViewEditDefProcedure
; #### FUNCTION ####
; ===============================================================================================
; Name : _GUICtrlListView_GetEditArrayIndex
; Description : Retrieves the index of the edit control in ListView edit control array.
; Parameter(s) : $hListView - Handle to the window.
; Return values : Returns 1-based value if succeeds, otherwise 0.
; Author : Pusofalse
; ===============================================================================================
Func _GUICtrlListView_GetEditArrayIndex($hListView)
If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle(-1)
For $i = 1 To $a_ListViewEditControls[0][0]
If ($hListView = $a_ListViewEditControls[$i][0]) Then Return $i
Next
Return 0
EndFunc ;==>_GUICtrlListView_GetEditArrayIndex
; #### FUNCTION ####
; ===============================================================================================
; Name : _GUICtrlListView_RegisterEditEvent
; Description : Register Edit notification for a ListView Window.
; Parameter(s) : $hListView - Handle to the window.
; : $fAutoComplete - A BOOL value indicates that whether save the result automatically when finishing the input.
; Return values : True is returned if succeeds, else False.
; Author : Pusofalse
; ===============================================================================================
Func _GUICtrlListView_RegisterEditEvent($hListView, $fAutoComplete = 1)
If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)
If (_GUICtrlListView_GetEditArrayIndex($hListView)) Then Return 1
$a_ListViewEditControls[0][0] += 1
ReDim $a_ListViewEditControls[$a_ListViewEditControls[0][0] + 1][4]
$a_ListViewEditControls[$a_ListViewEditControls[0][0]][0] = $hListView
$a_ListViewEditControls[$a_ListViewEditControls[0][0]][1] = GUICtrlCreateInput("", 0, 0, 20, 18)
$a_ListViewEditControls[$a_ListViewEditControls[0][0]][2] = GUICtrlGetHandle(-1)
$a_ListViewEditControls[$a_ListViewEditControls[0][0]][3] = $fAutoComplete
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetFont(-1, 8.8, 400, 0, "Verdana")
_WinAPI_SetParent($a_ListViewEditControls[$a_ListViewEditControls[0][0]][2], $hListView)
Local $aAccelerator[1][2] = [["{enter}", $a_ListViewEditControls[$a_ListViewEditControls[0][0]][1]]]
GUISetAccelerators($aAccelerator)
If ($a_ListViewEditControls[0][0] = 1) Then
$h_ListViewEditDefCall = _WinAPI_SetWindowLong( _
$a_ListViewEditControls[$a_ListViewEditControls[0][0]][2], -4, $p_ListViewEditDefProcedure)
$h_ListViewDefCall = _WinAPI_SetWindowLong($hListView, -4, $p_ListViewDefProcedure)
Else
_WinAPI_SetWindowLong( _
$a_ListViewEditControls[$a_ListViewEditControls[0][0]][2], -4, $p_ListViewEditDefProcedure)
_WinAPI_SetWindowLong($hListView, -4, $p_ListViewDefProcedure)
EndIf
Return 1
EndFunc ;==>_GUICtrlListView_RegisterEditEvent
Func _GUICtrlListView_EditItem($hListView, $iItem, $iSubItem = 0)
Local $aRect, $iLeft, $iTop, $iWidth, $iHeight, $iEditId, $hEdit, $sText
If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)
$i_ListViewEditItem = -1
$i_ListViewEditSubItem = -1
For $i = 1 To $a_ListViewEditControls[0][0]
If ($a_ListViewEditControls[$i][0] = $hListView) Then
$iEditId = $a_ListViewEditControls[$i][1]
$hEdit = $a_ListViewEditControls[$i][2]
ExitLoop
EndIf
Next
If ($iEditId = 0) Then Return SetError(1, 0, 0)
$aRect = _GUICtrlListView_GetItemRect($hListView, $iItem)
If (IsArray($aRect) = 0) Then Return SetError(1, 0, 0)
$iLeft = $aRect[0]
$iTop = $aRect[1]
$iHeight = $aRect[3] - $iTop
For $i = 0 To $iSubItem - 1
$iLeft += _GUICtrlListView_GetColumnWidth($hListView, $i)
Next
$iWidth = _GUICtrlListView_GetColumnWidth($hListView, $iSubItem)
$i_ListViewEditItem = $iItem
$i_ListViewEditSubItem = $iSubItem
$sText = _GUICtrlListView_GetItemText($hListView, $iItem, $iSubItem)
GUICtrlSetData($iEditId, $sText)
GUICtrlSetPos($iEditId, $iLeft, $iTop, $iWidth, $iHeight)
Return GUICtrlSetState($iEditId, BitOR($GUI_SHOW, $GUI_FOCUS))
EndFunc ;==>_GUICtrlListView_EditItem
Func _GUICtrlListView_UnregisterEditEvent($hListView)
Local $iIndex
$iIndex = _GUICtrlListView_GetEditArrayIndex($hListView)
If ($iIndex = 0) Then Return 0
GUICtrlDelete($a_ListViewEditControls[$iIndex][1])
$a_ListViewEditControls[$iIndex][0] = 0
$a_ListViewEditControls[$iIndex][1] = 0
$a_ListViewEditControls[$iIndex][2] = 0
$a_ListViewEditControls[$iIndex][3] = 0
Return 1
EndFunc ;==>_GUICtrlListView_UnregisterEditEvent
Func _GUICtrlListView_GetEditId($hListView)
If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)
Local $iIndex = _GUICtrlListView_GetEditArrayIndex($hListView)
If ($iIndex = 0) Then Return 0
Return $a_ListViewEditControls[$iIndex][1]
EndFunc ;==>_GUICtrlListView_GetEditId
Func _GUICtrlListView_GetEditData($hListView)
If Not IsHWnd($hListView) Then $hListView = GUICtrlGetHandle($hListView)
Local $iEditId = _GUICtrlListView_GetEditID($hListView)
If ($iEditId = 0) Then Return SetError(1, 0, "")
Return GUICtrlRead($iEditId)
EndFunc ;==>_GUICtrlListView_GetEditData
Func _GUICtrlListView_SetEditData($hListView, $vData = "", $fAppend = 0)
Local $iEditId
$iEditId = _GUICtrlListView_GetEditID($hListView)
Return GUICtrlSetData($iEditId, $vData, $fAppend)
EndFunc ;==>_GUICtrlListView_SetEditData
Func _GUICtrlListView_CancelEdit($hListView)
Local $iIndex, $sText, $tText, $pText, $tBuffer, $pBuffer, $iLength, $hParent, $iListView
$iIndex = _GUICtrlListView_GetEditArrayIndex($hListView)
If ($iIndex = 0) Then Return SetError(1, 0, 0)
$iEditId = $a_ListViewEditControls[$iIndex][1]
If ($iEditId = 0) Then Return SetError(1, 0, 0)
If BitAND(GUICtrlGetState($iEditId), $GUI_HIDE) = $GUI_HIDE Then Return 0
$iListView = _WinAPI_GetDlgCtrlID($hListView)
$hParent = _WinAPI_GetParent($hListView)
$sText = GUICtrlRead($iEditId)
$iLength = StringLen($sText) + 2
$tText = DllStructCreate("wchar Text[" & $iLength & "]")
$pText = DllStructGetPtr($tText)
$tBuffer = DllStructCreate($tagLISTVIEW_EDITEND)
$pBuffer = DllStructGetPtr($tBuffer)
DllStructSetData($tText, "Text", $sText)
DllStructSetData($tBuffer, "hWndFrom", $hListView)
DllStructSetData($tBuffer, "IDFrom", $iListView)
DllStructSetData($tBuffer, "Code", $LVN_EDITEND)
DllStructSetData($tBuffer, "Item", $i_ListViewEditItem)
DllStructSetData($tBuffer, "SubItem", $i_ListViewEditSubItem)
DllStructSetData($tBuffer, "EndFlags", $LVEF_CANCEL)
DllStructSetData($tBuffer, "Length", $iLength)
DllStructSetData($tBuffer, "Text", $pText)
DllStructSetData($tBuffer, "AutoComplete", $a_ListViewEditControls[$iIndex][3])
$f_ListViewEditMsgIsSending = 1
_WinAPI_PostMessage($hParent, $WM_NOTIFY, $iListView, $pBuffer)
If (DllStructGetData($tBuffer, "AutoComplete") <> 0) Then
Local $tTextReturn
$iLength = DllStructGetData($tBuffer, "Length")
$pText = DllStructGetData($tBuffer, "Text")
$tTextReturn = DllStructCreate("wchar Text[" & $iLength & "]", $pText)
$sText = DllStructGetData($tTextReturn, "Text")
$tTextReturn = 0
_GUICtrlListView_SetItemText($hListView, $i_ListViewEditItem, $sText, $i_ListViewEditSubItem)
EndIf
$tText = 0
GUICtrlSetState($iListView, $GUI_FOCUS)
GUICtrlSetState($iEditId, $GUI_HIDE)
$f_ListViewEditMsgIsSending = 0
Return 1
EndFunc ;==>_GUICtrlListView_CancelEdit
Func _GUICtrlListView_SetEditAutoComplete($hListView, $fAutoComplete = 1)
Local $iIndex = _GUICtrlListView_GetEditArrayIndex($hListView)
If ($iIndex = 0) Then Return SetError(1, 0, 0)
$a_ListViewEditControls[$iIndex][3] = $fAutoComplete
Return 1
EndFunc ;==>_GUICtrlListView_SetEditAutoComplete
|