回复 6# 131738
测试了一下还发现这个问题:
#include <GuiListView.au3>
GUICreate("ListView Find Text", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState()
_GUICtrlListView_AddColumn($hListView, "Items", 100)
_GUICtrlListView_BeginUpdate($hListView)
For $iI = 4 To 49
_GUICtrlListView_AddItem($hListView, "en" & $iI)
Next
_GUICtrlListView_AddItem($hListView, "中文Target item")
For $iI = 51 To 100
_GUICtrlListView_AddItem($hListView, "Item " & $iI)
Next
_GUICtrlListView_AddItem($hListView, "end")
_GUICtrlListView_EndUpdate($hListView)
; 搜索目标项目
$iI = __GUICtrlListView_FindText($hListView, "文", -1, 1)
MsgBox(4160, "1", "Target Item Index: " & $iI)
If $iI <> -1 Then _GUICtrlListView_EnsureVisible($hListView, $iI)
$iI = __GUICtrlListView_FindText($hListView, "文", -1, 0)
MsgBox(4160, "2", "Target Item Index: " & $iI)
If $iI <> -1 Then _GUICtrlListView_EnsureVisible($hListView, $iI)
$iI = __GUICtrlListView_FindText($hListView, "中", -1, 1)
MsgBox(4160, "3", "Target Item Index: " & $iI)
If $iI <> -1 Then _GUICtrlListView_EnsureVisible($hListView, $iI)
$iI = __GUICtrlListView_FindText($hListView, "中", -1, 0)
MsgBox(4160, "4", "Target Item Index: " & $iI)
If $iI <> -1 Then _GUICtrlListView_EnsureVisible($hListView, $iI)
$iI = __GUICtrlListView_FindText($hListView, "Target", -1, 1)
MsgBox(4160, "5", "Target Item Index: " & $iI)
If $iI <> -1 Then _GUICtrlListView_EnsureVisible($hListView, $iI)
$iI = __GUICtrlListView_FindText($hListView, "Target", -1, 0)
MsgBox(4160, "6", "Target Item Index: " & $iI)
If $iI <> -1 Then _GUICtrlListView_EnsureVisible($hListView, $iI)
Do
Until GUIGetMsg() = -3
GUIDelete()
Func __GUICtrlListView_FindText($hWnd, $sText, $iStart = -1, $fPartialOK = True, $fWrapOK = True)
Local $tFindInfo = DllStructCreate($tagLVFINDINFO)
Local $iFlags = $LVFI_STRING
;~ Local $iFlags = $LVFI_SUBSTRING
If $fPartialOK Then $iFlags = BitOR($iFlags, $LVFI_SUBSTRING)
If $fWrapOK Then $iFlags = BitOR($iFlags, $LVFI_WRAP)
DllStructSetData($tFindInfo, "Flags", $iFlags)
Return __GUICtrlListView_FindItem($hWnd, $iStart, $tFindInfo, $sText)
EndFunc ;==>__GUICtrlListView_FindText
Func __GUICtrlListView_FindItem($hWnd, $iStart, ByRef $tFindInfo, $sText = "")
Local $sBinText = StringToBinary($sText, 1)
Local $iBuffer = BinaryLen($sBinText) + 1
Local $tBuffer = DllStructCreate("byte Text[" & $iBuffer & "]")
Local $pBuffer = DllStructGetPtr($tBuffer)
DllStructSetData($tBuffer, "Text", $sBinText)
Local $iRet
If IsHWnd($hWnd) Then
If _WinAPI_InProcess($hWnd, $__g_hLVLastWnd) Then
DllStructSetData($tFindInfo, "Text", $pBuffer)
$iRet = _SendMessage($hWnd, $LVM_FINDITEM, $iStart, $tFindInfo, 0, "wparam", "struct*")
Else
Local $iFindInfo = DllStructGetSize($tFindInfo)
Local $tMemMap
Local $pMemory = _MemInit($hWnd, $iFindInfo + $iBuffer, $tMemMap)
Local $pText = $pMemory + $iFindInfo
DllStructSetData($tFindInfo, "Text", $pText)
_MemWrite($tMemMap, $tFindInfo, $pMemory, $iFindInfo)
_MemWrite($tMemMap, $tBuffer, $pText, $iBuffer)
$iRet = _SendMessage($hWnd, $LVM_FINDITEM, $iStart, $pMemory, 0, "wparam", "ptr")
_MemFree($tMemMap)
EndIf
Else
DllStructSetData($tFindInfo, "Text", $pBuffer)
$iRet = GUICtrlSendMsg($hWnd, $LVM_FINDITEM, $iStart, DllStructGetPtr($tFindInfo))
EndIf
Return $iRet
EndFunc ;==>__GUICtrlListView_FindItem
Func __GUICtrlListView_FindItemAfan($hWnd, $iStart, ByRef $tFindInfo, $sText = '')
Local $aSR = StringRegExp($sText, '[^\x00-\xff]', 3), $iL = UBound($aSR)
Local $iBuffer = StringLen($sText) + 1 + $iL
Local $tBuffer = DllStructCreate('char Text[' & $iBuffer & ']')
Local $pBuffer = DllStructGetPtr($tBuffer)
For $i = 0 To $iL - 2
$sText &= ' '
Next
DllStructSetData($tBuffer, 'Text', $sText)
Local $iRet
If IsHWnd($hWnd) Then
If _WinAPI_InProcess($hWnd, $__g_hLVLastWnd) Then
DllStructSetData($tFindInfo, 'Text', $pBuffer)
ConsoleWrite('222')
$iRet = _SendMessage($hWnd, $LVM_FINDITEM, $iStart, $tFindInfo, 0, 'wparam', 'struct*')
Else
Local $iFindInfo = DllStructGetSize($tFindInfo)
Local $tMemMap
Local $pMemory = _MemInit($hWnd, $iFindInfo + $iBuffer, $tMemMap)
Local $pText = $pMemory + $iFindInfo
DllStructSetData($tFindInfo, 'Text', $pText)
_MemWrite($tMemMap, $tFindInfo, $pMemory, $iFindInfo)
_MemWrite($tMemMap, $tBuffer, $pText, $iBuffer)
ConsoleWrite('0000')
$iRet = _SendMessage($hWnd, $LVM_FINDITEM, $iStart, $pMemory, 0, 'wparam', 'ptr')
_MemFree($tMemMap)
EndIf
Else
DllStructSetData($tFindInfo, 'Text', $pBuffer)
ConsoleWrite('111111111')
$iRet = GUICtrlSendMsg($hWnd, $LVM_FINDITEM, $iStart, DllStructGetPtr($tFindInfo))
EndIf
Return $iRet
EndFunc ;==>__GUICtrlListView_FindItemAfan
|