本帖最后由 happytc 于 2012-6-24 21:01 编辑
回复 1# txm888
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
Global $hListview
Global $aItemData[10] = ["Name1|192.168.1.5|999999991|PC0|00112233FE", _
"Name2|192.168.1.4|999999993|PC2|00112233BD", _
"Name3|192.168.1.3|999999995|PC4|00112233AC", _
"Name4|192.168.1.2|999999992|PC1|00112233F0", _
"Name5|192.168.1.1|999999994|PC3|00112233E8", _
"Name6|192.168.1.6|999999996|PC6|00112233E9", _
"Name7|192.168.1.7|999999997|PC7|00112233EA", _
"Name8|192.168.1.8|999999998|PC8|00112233EB", _
"Name9|192.168.1.9|999999999|PC9|00112233EC", _
"Name0|192.168.1.0|999999990|PC10|00112233ED"]
_Main()
Func _Main()
Local $iExListViewStyle, $iExListViewStyle, $hGUI
Local $aColWidths[5] = [150, 150, 150, 250, 200]
$iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE)
$iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_DOUBLEBUFFER)
$hGUI = GUICreate("ListView Sort", 920, 300)
$hListview = _GUICtrlListView_Create($hGUI, "Domain Device|IP Address|Serial Number|Description|Mac Address", 5, 5, 910, 250, $LVS_REPORT, $iExWindowStyle)
_GUICtrlListView_SetExtendedListViewStyle($hListview, $iExListViewStyle)
For $i = 0 To UBound($aColWidths) - 1
_GUICtrlListView_SetColumnWidth($hListview, $i, $aColWidths[$i])
Next
_GUICtrlListView_SetBkColor($hListview, 0xA6CAF0)
_GUICtrlListView_JustifyColumn($hListview, 4, 2)
_FillItems()
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState()
_GUICtrlListView_RegisterSortCallBack($hListview, True, True)
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
_GUICtrlListView_UnRegisterSortCallBack($hListview)
GUIDelete()
EndFunc
Func _FillItems()
Local $aSplit
For $i = 0 To UBound($aItemData) - 1
$aSplit = StringSplit($aItemData[$i], "|")
_GUICtrlListView_AddItem($hListview, $aSplit[1], -1, _GUICtrlListView_GetItemCount($hListview) )
For $j = 2 To $aSplit[0]
_GUICtrlListView_AddSubItem($hListview, $i, $aSplit[$j], $j - 1)
Next
Next
EndFunc
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hListview
Switch $iCode
Case $LVN_COLUMNCLICK
Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
Local $iCol = DllStructGetData($tInfo, "SubItem")
_GUICtrlListView_SortItems($hWndFrom, $iCol)
EndSwitch
EndSwitch
Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
EndFunc
|