- Offizieller Beitrag
Mir ist gerade aufgefallen, dass die Funktion "_GUICtrlListView_GetSelectedIndices" bei Array-Rückgabe noch ein ReDim innerhalb der For...Next-Schleife benutzt.
Das ist ziemlich zeitfressend, wenn man viele Listview-Einträge benutzt. Deshalb habe ich die Funktion mal umgeschrieben. Das Ergebnis ist umso gravierender, je mehr Listview-Einträge vorhanden sind:
Spoiler anzeigen
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <SendMessage.au3>
$hGui = GUICreate('Listview-Test', 400, 600)
$hListView = GUICtrlCreateListView('a|b|c|d', 5, 5, 390, 590, $LVS_SHOWSELALWAYS)
For $i = 0 To 4999
$sItem = Random(1000, 9999, 1) & '|' & Random(1000, 9999, 1) & '|' & Random(1000, 9999, 1) & '|' & Random(1000, 9999, 1)
GUICtrlCreateListViewItem($sItem, $hListView)
Next
GUISetState()
$hWndLV = GUICtrlGetHandle($hListView)
_GUICtrlListView_SetItemSelected($hWndLV, -1, True)
$iTimer = TimerInit()
$aSelIndices = _GUICtrlListView_GetSelectedIndices($hListView, True) ; das Original
ConsoleWrite('Original: ' & TimerDiff($iTimer) & @CR)
$iTimer = TimerInit()
$aSelIndices = _GUICtrlListView_GetSelectedIndicesNew($hListView, True) ; die modifizierte Version (unten)
ConsoleWrite('Modifiziert: ' & TimerDiff($iTimer) & @CR)
Do
Until GUIGetMsg() = -3
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlListView_GetSelectedIndicesNew
; Description ...: Retrieve indices of selected item(s)
; Syntax.........: _GUICtrlListView_GetSelectedIndices($hWnd, $fArray = False)
; Parameters ....: $hWnd - Handle to the control
; $fArray - Return string or Array
; |True - Returns array
; |False - Returns pipe "|" delimited string
; Return values .: Success - Selected indices Based on $fArray:
; +Array - With the following format
; |[0] - Number of Items in array (n)
; |[1] - First item index
; |[2] - Second item index
; |[n] - Last item index
; |String - With the following format
; |"0|1|2|n"
; Failure - Based on $fArray
; |Array - With the following format
; |[0] - Number of Items in array (0)
; |String - Empty ("")
; Author ........: Gary Frost (gafrost)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _GUICtrlListView_GetSelectedIndicesNew($hWnd, $fArray = False)
If $Debug_LV Then __UDF_ValidateClassName($hWnd, $__LISTVIEWCONSTANT_ClassName)
Local $sIndices, $iRet, $iCount = _GUICtrlListView_GetItemCount($hWnd)
For $iItem = 0 To $iCount
If IsHWnd($hWnd) Then
$iRet = _SendMessage($hWnd, $LVM_GETITEMSTATE, $iItem, $LVIS_SELECTED)
Else
$iRet = GUICtrlSendMsg($hWnd, $LVM_GETITEMSTATE, $iItem, $LVIS_SELECTED)
EndIf
If $iRet Then $sIndices &= $iItem & '|'
Next
If $fArray Then Return StringSplit(StringTrimRight($sIndices, 1), '|')
Return StringTrimRight($sIndices, 1)
EndFunc ;==>_GUICtrlListView_GetSelectedIndices