回复 7# netegg
這樣說我就懂了~~~感謝 !!
雖然如此 可是實際應用其實 還是得想個其他方法 因為 原本
虛擬列表 10000 筆數據 只要不到一秒鐘
加上 這個判斷後 卡住了 停頓好幾秒
請看 代碼
;~ 關於虛擬列表的一份說明
;~ http://blog.vckbase.com/iwaswzq/archive/2006/07/07/21113.aspx
#cs ____________________________________
Au3 版本: 3.3.9.0
腳本作者: CrossDoor
電子郵件: 382869232@qq.com
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>
#include <FontConstants.au3>
Global $Font1 = _WinAPI_CreateFont(14, 0, 0, 0, $FW_BOLD)
Global $Font2 = _WinAPI_CreateFont(14, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, _
$CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "MS Sans Serif")
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)
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 $LVN_COLUMNCLICK ; 點擊列頭排序
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
$iSub = DllStructGetData($tInfo, "SubItem")
_ArraySort($aShowdata, $B_DESCENDING[$iSub], 0, 0, $iSub)
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
$B_DESCENDING[$iSub] = Not $B_DESCENDING[$iSub]
Case $NM_DBLCLK ; 按兩下
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$iIndex = DllStructGetData($tInfo, "Index")
$iSub = DllStructGetData($tInfo, "SubItem")
MsgBox(0, $iIndex, $aShowdata[$iIndex][$iSub])
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
;If $aShowdata[$iIndex][0]="爺爺10" Then $iSTR=$iIndex
DllStructSetData($tText, "Text", $s);列資料放入$tText結構
DllStructSetData($tInfo, "Text", DllStructGetPtr($tText));用$tText結構的指標來設置列資料
DllStructSetData($tInfo, "TextMax", StringLen($s));設置列數據長度
Case $NM_CUSTOMDRAW
;For $i = 0 To UBound($aShowdata) - 1 Step 1
;If $aShowdata[$i][0]="爺爺10" Then
Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam)
Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage")
If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW
If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW
Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem")
Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
Local $iColor, $hDC
#cs
Switch $iItem
Case $iIndex
$hDC = DllStructGetData($tCustDraw, "hdc")
If $iSubItem = 0 Then
$iColor = RGB2BGR(0xFF0000)
_WinAPI_SelectObject($hDC, $Font1)
DllStructSetData($tCustDraw, "clrText", $iColor)
ElseIf $iSubItem = 1 Then
$iColor = RGB2BGR(0x000000)
_WinAPI_SelectObject($hDC, $Font2)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(0xFFFF80))
ElseIf $iSubItem = 2 Then
$iColor = RGB2BGR(0x008080)
_WinAPI_SelectObject($hDC, $Font1)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(0xFFFFFF))
EndIf
Return $CDRF_NEWFONT
EndSwitch
#ce
;#cs
For $i = 0 To UBound($aShowdata) - 1 Step 1
If $aShowdata[$i][0]="爺爺10" Then
Switch $iItem
Case $i
$hDC = DllStructGetData($tCustDraw, "hdc")
If $iSubItem = 0 Then
$iColor = RGB2BGR(0xFF0000)
_WinAPI_SelectObject($hDC, $Font1)
DllStructSetData($tCustDraw, "clrText", $iColor)
ElseIf $iSubItem = 1 Then
$iColor = RGB2BGR(0x000000)
_WinAPI_SelectObject($hDC, $Font2)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(0xFFFF80))
ElseIf $iSubItem = 2 Then
$iColor = RGB2BGR(0x008080)
_WinAPI_SelectObject($hDC, $Font1)
DllStructSetData($tCustDraw, "clrText", $iColor)
DllStructSetData($tCustDraw, "clrTextBk", RGB2BGR(0xFFFFFF))
EndIf
Return $CDRF_NEWFONT
EndSwitch
EndIf
Next
;#ce
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func RGB2BGR($iColor)
Return BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
EndFunc ;==>RGB2BGR()
|