#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
Global $gui, $list1, $list2
Global $hListView1,$hListView2,$listViewNum
Global $aItem
$gui = GUICreate($gui, 1000, 400)
$bt1 = GUICtrlCreateButton('切换1', 20, 270, 60, 20)
$bt2 = GUICtrlCreateButton('切换2', 100, 270, 60, 20)
Dim $iCombo = GUICtrlCreateCombo('', -100, -100)
list1()
list2()
GUISetState()
GUIRegisterMsg(0x004E, '_WM_NOTIFY') ;$WM_NOTIFY = 0x004E
Local $id1 = GUICtrlCreateDummy()
Local $aAccelKeys[1][2]= [['{Enter}', $id1]]
GUISetAccelerators($aAccelKeys)
Func _UdpData()
If Not IsArray($aItem) Then Return
Local $sRd = GUICtrlRead($iCombo), $sData = ''
;_GUICtrlListView_SetItemText($hListView1, $aItem[0], $sRd, $aItem[1]) ;单listview
Switch $listViewNum
Case 1
_GUICtrlListView_SetItemText($hListView1, $aItem[0], $sRd, $aItem[1]) ;多listView
Case 2
_GUICtrlListView_SetItemText($hListView2, $aItem[0], $sRd, $aItem[1]) ;多listView
Case 3
EndSwitch
GUICtrlSetPos($iCombo, -1000, -100)
;~ MsgBox(262144,'','激活了快捷键',1)
EndFunc ;==>_UdpData
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $bt1
GUICtrlSetState($list2, 32)
GUICtrlSetState($list1, 16)
Case $bt2
GUICtrlSetState($list1, 32)
GUICtrlSetState($list2, 16)
Case $list1
_GUICtrlListView_SortItems($list1, GUICtrlGetState($list1))
Case $list2
_GUICtrlListView_SortItems($list2, GUICtrlGetState($list2))
Case $id1
_UdpData()
EndSwitch
WEnd
_GUICtrlListView_UnRegisterSortCallBack($list1)
_GUICtrlListView_UnRegisterSortCallBack($list2)
Func list1()
$list1 = GUICtrlCreateListView("英文 1|英文 2|英文 3", 10, 10, 280, 180)
Dim $hListView1 = GUICtrlGetHandle(-1)
_GUICtrlListView_AddItem($list1, 'aa')
_GUICtrlListView_AddSubItem($list1, 0, 'bb', 1)
_GUICtrlListView_AddSubItem($list1, 0, 'cc', 2)
_GUICtrlListView_AddItem($list1, 'dd')
_GUICtrlListView_AddSubItem($list1, 1, 'ee', 1)
_GUICtrlListView_AddSubItem($list1, 1, 'ff', 2)
_GUICtrlListView_RegisterSortCallBack($list1, 0)
EndFunc ;==>list1
Func list2()
$list2 = GUICtrlCreateListView("数字 1|数字 2|数字 3|数字 4", 510, 10, 280, 180)
Dim $hListView2 = GUICtrlGetHandle(-1)
_GUICtrlListView_AddItem($list2, '11')
_GUICtrlListView_AddSubItem($list2, 0, '22', 1)
_GUICtrlListView_AddSubItem($list2, 0, '233', 2)
_GUICtrlListView_AddSubItem($list2, 0, '144', 3)
_GUICtrlListView_AddItem($list2, '55')
_GUICtrlListView_AddSubItem($list2, 1, '66', 1)
_GUICtrlListView_AddSubItem($list2, 1, '77', 2)
_GUICtrlListView_AddSubItem($list2, 1, '88', 3)
_GUICtrlListView_RegisterSortCallBack($list2, 1)
EndFunc ;==>list2
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
Switch DllStructGetData($tNMHDR, 'hWndFrom')
Case $hListView1
$listViewNum = 1
Switch DllStructGetData($tNMHDR, 'Code')
Case -2
If IsArray($aItem) Then
_UdpData()
Else
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
If $SubItem = 2 Then
Local $context = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
Dim $hMenu = GUICtrlGetHandle($context)
GUICtrlCreateMenuItem('男', $context)
GUICtrlCreateMenuItem('女', $context)
Local $iid = _GUICtrlMenu_TrackPopupMenu($hMenu, $gui, -1, -1, 1, 1, 2)
If $iid Then _GUICtrlListView_SetItemText($hListView1, $index, _GUICtrlMenu_GetItemText($hMenu, $iid, False), 2)
EndIf
EndIf
Case -3
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
Dim $aItem = 0
If Not StringRegExp($SubItem, "^(0|1|2)[ DISCUZ_CODE_0 ]quot;) Then Return 'GUI_RUNDEFMSG'
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView1, $index, $SubItem)
Dim $aItem[2] = [$index, $SubItem]
Local $sDef
Local $sData = _GUICtrlListView_GetItemText($hListView1, $index, $SubItem)
GUICtrlSetPos($iCombo , $aRect[0] + 4 , $aRect[1] + 12 ,$aRect[2] - $aRect[0])
GUICtrlSetData($iCombo, '|' & $sData & '|' & $sDef, $sData)
GUICtrlSetState($iCombo, 256)
EndSwitch
Case $hListView2
$listViewNum = 2
Switch DllStructGetData($tNMHDR, 'Code')
Case -2
If IsArray($aItem) Then
_UdpData()
Else
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
If $SubItem = 3 Then
Local $context = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
Dim $hMenu = GUICtrlGetHandle($context)
GUICtrlCreateMenuItem('男', $context)
GUICtrlCreateMenuItem('女', $context)
Local $iid = _GUICtrlMenu_TrackPopupMenu($hMenu, $gui, -1, -1, 1, 1, 2)
If $iid Then _GUICtrlListView_SetItemText($hListView2, $index, _GUICtrlMenu_GetItemText($hMenu, $iid, False), 3)
EndIf
EndIf
Case -3
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $index = DllStructGetData($tInfo, 'Index')
Local $SubItem = DllStructGetData($tInfo, 'SubItem')
Dim $aItem = 0
If Not StringRegExp($SubItem, "^(0|1|2)[ DISCUZ_CODE_0 ]quot;) Then Return 'GUI_RUNDEFMSG'
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView2, $index, $SubItem)
Dim $aItem[2] = [$index, $SubItem]
Local $sDef
Local $sData = _GUICtrlListView_GetItemText($hListView2, $index, $SubItem)
GUICtrlSetPos($iCombo , $aRect[0] + 504 , $aRect[1] + 12 ,$aRect[2] - $aRect[0])
GUICtrlSetData($iCombo, '|' & $sData & '|' & $sDef, $sData)
GUICtrlSetState($iCombo, 256)
EndSwitch
EndSwitch
EndFunc ;==>_WM_NOTIFY