找回密码
 加入
搜索
查看: 3952|回复: 10

[AU3基础] 【已解决】关于获取DLL内部图标数量

  [复制链接]
发表于 2011-1-18 16:41:11 | 显示全部楼层 |阅读模式
本帖最后由 chenronting 于 2011-1-22 20:01 编辑

上面那个函数是用来选择ICO图标的,现在想请教一个问题:
不知道能不能得到Dll的内部图标数量?
在论坛里搜索了下没有发现这方面的东西
希望知道的能来回答到, 谢谢

谢谢下面几位回答者。

最完美的答案在 9#,

评分

参与人数 1金钱 +10 收起 理由
pusofalse + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2011-1-18 17:03:03 | 显示全部楼层
参考下这段代码:
Func _ChooseIcon($sDll_File = "\shell32.dll")
    $sDll_File = @SystemDir & $sDll_File
    If Not FileExists($sDll_File) Then
        SetError(1)
        Return -1
    EndIf
    Local $sscInt = DllStructCreate("int")
    Local $sscString = DllStructCreate("wchar[260]")
    Local $sstructsize = DllStructGetSize($sscString) / 2
    DllStructSetData($sscString, 1, $sDll_File)
    DllCall("shell32.dll", "none", 62, "hwnd", 0, "ptr", DllStructGetPtr($sscString), "int", $sstructsize, "ptr", DllStructGetPtr($sscInt))
    If @error Then
        SetError(2)
        Return -1
    EndIf
    Local $nIconIndex = DllStructGetData($sscInt, 1)
    If @error <> 0 Then
        SetError(3)
        Return -1
    EndIf
    Return $nIconIndex
EndFunc   ;==>_ChooseIcon

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
Global $iIconIndex

; Example:

$iIconIndex = _ChooseIcon("\shell32.dll") ; Loads the DLL file: [@SystemDir]\shell32.dll

MsgBox(64, "_ChooseIcon Example", "Icon ID: " & $iIconIndex)
发表于 2011-1-18 17:27:27 | 显示全部楼层
不错 学习了。。。。
 楼主| 发表于 2011-1-18 19:08:59 | 显示全部楼层
回复 2# smartzbs


    这个还真看不太懂,不知道在这里面如何得到数量?帮助我吧。谢谢
发表于 2011-1-18 19:29:24 | 显示全部楼层
把标题改了就告诉你。
发表于 2011-1-19 16:57:41 | 显示全部楼层
有个笨办法:
#Include <WinAPI.au3>

$sIcon = @SystemDir & '\shell32.dll'
$iIndex = 0
While 1
        $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', 0, 'int', 0, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)
        If (@error) Or ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then
                ;$iIndex -= 1
                ExitLoop
        EndIf
        _WinAPI_DestroyIcon($Ret[5])
        $iIndex += 1
WEnd
ConsoleWrite("总数:"&$iIndex&",范围:0-"&$iIndex-1&@CRLF)
发表于 2011-1-19 22:28:13 | 显示全部楼层
不针对问题,只针对上一楼的代码,改为折半效率高.
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
 楼主| 发表于 2011-1-21 11:26:21 | 显示全部楼层
回复 7# 阿福


    使用是的测试法?呵呵, 感谢回答
 楼主| 发表于 2011-1-21 11:26:26 | 显示全部楼层
回复 6# smartzbs


      使用是的测试法?呵呵, 感谢回答
发表于 2011-1-21 20:32:06 | 显示全部楼层
本帖最后由 pusofalse 于 2011-1-21 20:58 编辑

$iTotalNumber = DllCall("Shell32.dll", "long", "ExtractIcon", "ptr", 0, "str", "Shell32.dll", "int", -1)
MsgBox(0, "", $iTotalNumber[0])
 楼主| 发表于 2011-1-22 19:59:54 | 显示全部楼层
回复 10# pusofalse


    感谢P版的帮助 。呵呵, 同样感谢前面两位童鞋。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-2 16:19 , Processed in 0.101678 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表