发现_GUICtrlListView_FindText搜索有个BUG,不支持中文完全匹配,问题续(已解决)
本帖最后由 txm888 于 2014-5-2 12:36 编辑上次提到的_GUICtrlListView_FindText搜索项目包含中文就无法匹配的问题,A版解决了,但我继续测试了下
发现在3.3.8.1版本下测试正常,而3.3.6.1的版本就不正常了,返回的总是空索引,其它版本未测试
问题原形:http://www.autoitx.com/thread-43912-1-2.html
截图如下:
请A版再帮看看,谢谢了,如果只能在3.3.8.1的版本下解决这问题也行,就免得再折腾了,反正总有一个行
2014.05.02更新
以下测试从 3.3.6.1 到 3.3.10.2 均正常#include <GuiListView.au3>
GUICreate("ListView Find Text", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState()
_GUICtrlListView_AddColumn($hListView, "Items", 100)
_GUICtrlListView_BeginUpdate($hListView)
_GUICtrlListView_AddItem($hListView, "我爱你123" & 1)
_GUICtrlListView_AddItem($hListView, "123我爱你" & 2)
_GUICtrlListView_AddItem($hListView, "你爱我abc3")
For $iI = 4 To 49
_GUICtrlListView_AddItem($hListView, "你爱我" & $iI)
Next
_GUICtrlListView_AddItem($hListView, "Target item")
For $iI = 51 To 100
_GUICtrlListView_AddItem($hListView, "Item " & $iI)
Next
_GUICtrlListView_AddItem($hListView, "你爱d")
_GUICtrlListView_EndUpdate($hListView)
; 搜索目标项目
$iI = __GUICtrlListView_FindText($hListView, "你爱d", -1, true)
MsgBox(4160, "Information", "Target Item Index: " & $iI)
_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
If $fPartialOK Then $iFlags = BitOR($iFlags, $LVFI_PARTIAL)
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 $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, $_lv_ghLastWnd) 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
回复 2# afan
忘了说,List控件是用自定义UDF创建的,_GUICtrlListView_Create,因为要用到自动排序功能
用3.3.6.1搜索,返回空,
如果用GUICtrlCreateListView创建的控件,所有版本都有效{:face (207):} 现在为求速度!基本都用UDF ,_GUICtrlListView_Create 来建了!朋友这么不用呢! List的Item如果是用UDF创建的话,返回的不是控件ID,而是类似句柄的一种二进制。印象里是这样的。 回复 4# f4李文杨
我就是这个UDF建的哦 回复 5# skyfree
可能与这有关系,想象也应该是这样 回复skyfree
可能与这有关系,想象也应该是这样
txm888 发表于 2014-4-30 09:25 http://www.autoitx.com/images/common/back.gif
还没解决吗?你也太关心你的帖子了…Func _GUICtrlListView_FindItem($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)
Local $pFindInfo = DllStructGetPtr($tFindInfo)
For $i = 0 To $iL - 2
$sText &= ' '
Next
DllStructSetData($tBuffer, 'Text', $sText)
Local $iRet
If IsHWnd($hWnd) Then
If _WinAPI_InProcess($hWnd, $_lv_ghLastWnd) Then
DllStructSetData($tFindInfo, 'Text', $pBuffer)
$iRet = _SendMessage($hWnd, $LVM_FINDITEM, $iStart, $pFindInfo, 0, 'wparam', 'ptr')
Else
Local $iFindInfo = DllStructGetSize($tFindInfo)
Local $tMemMap
Local $pMemory = _MemInit($hWnd, $iFindInfo + $iBuffer, $tMemMap)
Local $pText = $pMemory + $iFindInfo
DllStructSetData($tFindInfo, 'Text', $pText)
_MemWrite($tMemMap, $pFindInfo, $pMemory, $iFindInfo)
_MemWrite($tMemMap, $pBuffer, $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, $pFindInfo)
EndIf
Return $iRet
EndFunc ;==>_GUICtrlListView_FindItem 回复 8# afan
完美解决了,太帅了A版,感谢感谢
页:
[1]