不针对问题,只针对上一楼的代码,改为折半效率高.Local $aNum[6], $sIcon, $t
$sIcon = @SystemDir & '\shell32.dll'
$aNum[0] = 0
$aNum[1] = 0xffffff ; $iIndex: int type
$aNum[2] = Ceiling(($aNum[1]+$aNum[0])/2)
$t=TimerInit()
While 1
$Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $aNum[2], 'int', 0, 'int', 0, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
If (@error) Or ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then
$aNum = _TwoValue($aNum, False)
Else
DllCall("user32.dll", "bool", "DestroyIcon", "handle", $Ret[5]);_WinAPI_DestroyIcon($Ret[5])
$aNum = _TwoValue($aNum, True)
EndIf
If $aNum[5] Then ExitLoop
WEnd;
$t=TimerDiff($t)
If IsNumber($aNum[4]) Then
ConsoleWrite("总数:" & $aNum[4]-$aNum[3]+1 & ",范围:" & $aNum[3] & "-" & $aNum[4] & ",用时" & $t &@CRLF)
Else
ConsoleWrite("没有Icon" & @CRLF)
EndIf
Func _TwoValue($aNum, $bCon = True)
Select
Case $bCon;中值结果为True
If Not IsNumber($aNum[3]) Then $aNum[3]=$aNum[0];记录最小有效
If $aNum[1] = $aNum[2] Then
$aNum[4] = $aNum[2];结束,成功,$aNum[4] IsNumber
$aNum[5] = True
Return $aNum
EndIf
$aNum[0] = $aNum[2];记录当前最小
Case Else
If $aNum[1] = $aNum[0] Then
$aNum[5] = True;结束,全没有,$aNum[4] Not IsNumber
Return $aNum
EndIf
If $aNum[1] = $aNum[2] Then
$aNum[1] = $aNum[0]
Else
$aNum[1] = $aNum[2];记录当前最大
EndIf
EndSelect
$aNum[2] = Ceiling(($aNum[1]+$aNum[0])/2)
Return $aNum
EndFunc
|