#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("listview测试", 288, 243, 401, 193)
$ListView1 = GUICtrlCreateListView("1|2|3|4", 8, 0, 273, 153)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 50)
GUICtrlCreateListViewItem("1|2|3|4", $ListView1)
GUICtrlCreateListViewItem("21|22|23|24", $ListView1)
GUICtrlCreateListViewItem("31|32|33|34", $ListView1)
GUICtrlCreateListViewItem("41|42|43|44", $ListView1)
GUICtrlCreateListViewItem("51|52|53|54", $ListView1)
$Input1 = GUICtrlCreateInput("", 8, 168, 121, 21)
$Input2 = GUICtrlCreateInput("", 160, 168, 121, 21)
$Input3 = GUICtrlCreateInput("", 8, 200, 121, 21)
$Input4 = GUICtrlCreateInput("", 160, 200, 121, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Dim $lyListView1
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
;=============
$tNMHDR = DllStructCreate($tagNMHDR, $LParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
;=============
Switch $IDFrom;选择产生事件的控件
Case $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
$Index = _GUICtrlListView_GetSelectedIndices($ListView1)
If Not StringLen($Index) Then; 这里用以判断是否选定了ListViewItem
Return
Else
GUICtrlSetData($Input1, _GUICtrlListView_GetItemText($ListView1, Number($Index), 0))
GUICtrlSetData($Input2, _GUICtrlListView_GetItemText($ListView1, Number($Index), 1))
GUICtrlSetData($Input3, _GUICtrlListView_GetItemText($ListView1, Number($Index), 2))
GUICtrlSetData($Input4, _GUICtrlListView_GetItemText($ListView1, Number($Index), 3))
EndIf
Case $NM_DBLCLK ; 双击
Case $NM_RCLICK ; 右击
Case $LVN_KEYDOWN
$tInfo = DllStructCreate($tagNMLVKEYDOWN, $LParam);$ilParam)
$psx = DllStructGetData($tInfo, "VKey")
;~ MsgBox(0,0,$psx)
If $psx = "21495846" Then;向上
$Index = _GUICtrlListView_GetSelectedIndices($ListView1)
If Not StringLen($Index) Then; 这里用以判断是否选定了ListViewItem
Return
Else
If Number(_GUICtrlListView_GetSelectedIndices($ListView1)) <> 0 Then
GUICtrlSetData($Input1, _GUICtrlListView_GetItemText($ListView1, Number($Index) - 1, 0))
GUICtrlSetData($Input2, _GUICtrlListView_GetItemText($ListView1, Number($Index) - 1, 1))
GUICtrlSetData($Input3, _GUICtrlListView_GetItemText($ListView1, Number($Index) - 1, 2))
GUICtrlSetData($Input4, _GUICtrlListView_GetItemText($ListView1, Number($Index) - 1, 3))
EndIf
EndIf
ElseIf $psx = "22020136" Then;向下
$Index = _GUICtrlListView_GetSelectedIndices($ListView1)
If Not StringLen($Index) Then; 这里用以判断是否选定了ListViewItem
Return
Else
If Number(_GUICtrlListView_GetSelectedIndices($ListView1)) <> Number(_GUICtrlListView_GetItemCount($ListView1)) - 1 Then
GUICtrlSetData($Input1, _GUICtrlListView_GetItemText($ListView1, Number($Index) + 1, 0))
GUICtrlSetData($Input2, _GUICtrlListView_GetItemText($ListView1, Number($Index) + 1, 1))
GUICtrlSetData($Input3, _GUICtrlListView_GetItemText($ListView1, Number($Index) + 1, 2))
GUICtrlSetData($Input4, _GUICtrlListView_GetItemText($ListView1, Number($Index) + 1, 3))
EndIf
EndIf
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY