; Script Start - Add your code below here
;~ 關於虛擬列表的一份說明
;~ [url]http://blog.vckbase.com/iwaswzq/archive/2006/07/07/21113.aspx[/url]
#cs ____________________________________
Au3 版本: 3.3.9.0
腳本作者: CrossDoor
電子郵件: [email]382869232@qq.com[/email]
QQ/TM: 382869232
#ce _______________腳本開始_________________
#Region ;**** 參數創建於 ACNWrapper_GUI ****
#PRE_UseX64=n
#EndRegion ;**** 參數創建於 ACNWrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <array.au3>
Global $B_DESCENDING[3] ; 排序用陣列
Local $tText = DllStructCreate("wchar Text[512]");建個結構,用來放listview列資料
Local $GUI, $hImage, $iITEM_COUNT = 10000
Local $sSomeString = ""
Local $aBoy[$iITEM_COUNT][3], $aGirl[$iITEM_COUNT][3]
For $i = 0 To $iITEM_COUNT - 1;初始化陣列
$aBoy[$i][0] = "爺爺" & $i
$aBoy[$i][1] = "爸爸" & $i
$aBoy[$i][2] = "兒子" & $i
$aGirl[$i][0] = "奶奶" & $i
$aGirl[$i][1] = "媽媽" & $i
$aGirl[$i][2] = "女兒" & $i
Next
Local $aShowdata = $aBoy
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$hGUI = GUICreate("ListView虛擬清單 載入[" & $iITEM_COUNT & "]數據", 500, 350)
$hListView = GUICtrlCreateListView("Item1|nSubItem1|nSubItem2", 2, 2, 494, 294, $LVS_SHOWSELALWAYS + $LVS_OWNERDATA, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT + $LVS_EX_DOUBLEBUFFER)
;設置列寬
GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 0, 150)
GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 1, 150)
GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 2, 150)
GUICtrlSendMsg($hListView, $LVM_SETITEMCOUNT, $iITEM_COUNT, 0);分配清單記憶體。 為什麼要這樣做?因為虛擬清單必須要知道資料總量
;創建並關聯圖像清單
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 115)
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
$Button1 = GUICtrlCreateButton("男", 20, 310, 75, 25)
$Button2 = GUICtrlCreateButton("女", 100, 310, 75, 25)
$Button3 = GUICtrlCreateButton("修改", 180, 310, 75, 25)
$Button4 = GUICtrlCreateButton("清空", 260, 310, 75, 25)
GUISetState()
Local $iCol
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case -3
ExitLoop
Case $Button1
$aShowdata = $aBoy
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
Case $Button2
$aShowdata = $aGirl
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
Case $Button3
If StringLen($sSomeString) Then
$sSomeString = ""
Else
$sSomeString = Asc(Random(48, 255, 1))
EndIf
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
Case $Button4
$aShowdata = 0
$iITEM_COUNT = 0
GUICtrlSendMsg($hListView, $LVM_SETITEMCOUNT, $iITEM_COUNT, 0)
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
Case $hListView ; 點擊列標題,排序
$iCol = GUICtrlGetState($hListView)
_ArraySort($aShowdata, $B_DESCENDING[$iCol], 0, 0, $iCol)
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
$B_DESCENDING[$iCol] = Not $B_DESCENDING[$iCol]
EndSwitch
WEnd
GUIDelete()
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $s
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Local $iIndex = DllStructGetData($tNMHDR, 'Index')
Switch $iIDFrom
Case $hListView
Switch $iCode
Case $NM_DBLCLK ; 按兩下
;~ Test() ; <== 在退出WM_NOTIFY之前無法讀取清單內容
AdlibRegister("Test", 10) ; <== 利用定時,先退出WM_NOTIFY再讀取則正常
Case - 150, -177 ;$LVN_GETDISPINFOA = -150, $LVN_GETDISPINFOW = -177
If Not IsArray($aShowdata) Then ContinueCase
$tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
$iIndex = Int(DllStructGetData($tInfo, "Item"))
$iSub = Int(DllStructGetData($tInfo, "SubItem"))
IF BitAND(DllStructGetData($tInfo, "Mask"), $LVIF_IMAGE) And $iSub = 0 THEN DllStructSetData($tInfo, "Image", 0);設置列圖像
$s = $aShowdata[$iIndex][$iSub] & "-" & $sSomeString
DllStructSetData($tText, "Text", $s);列資料放入$tText結構
DllStructSetData($tInfo, "Text", DllStructGetPtr($tText));用$tText結構的指標來設置列資料
DllStructSetData($tInfo, "TextMax", StringLen($s));設置列數據長度
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func Test() ; 讀取清單內容
AdlibUnRegister("Test")
Local $item = _GUICtrlListView_GetItemTextArray($hListView, -1) ; 讀取選擇的條目
If $item[0] >= 3 Then
MsgBox(0, "", $item[1] & "|" & $item[2] & "|" & $item[3])
EndIf
EndFunc