himself 发表于 2008-9-7 21:27:44

_GUIImageList_AddIcon函数的一个BUG?

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
        Local $listview, $hImage
        Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
       
        GUICreate("ImageList AddIcon", 400, 300)
        $listview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
        _GUICtrlListView_SetExtendedListViewStyle($listview, $exStyles)
        GUISetState()
       
        ; Load images
        $hImage = _GUIImageList_Create(16, 16, 5, 3)
        _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 110)
;如果 @SystemDir & "\shell32.dll", 110这文件没有图标,或者文件损坏了,程序就会停止执行,哪位有好的解决办法?        _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 131)
        _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 165)
        _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 168)
        _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 137)
        _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 146)
        _GUICtrlListView_SetImageList($listview, $hImage, 1)

        ; Add columns
        _GUICtrlListView_AddColumn($listview, "Column 1", 120)
        _GUICtrlListView_AddColumn($listview, "Column 2", 100)
        _GUICtrlListView_AddColumn($listview, "Column 3", 100)

        ; Add items
        _GUICtrlListView_AddItem($listview, "Row 1: Col 1", 0)
        _GUICtrlListView_AddSubItem($listview, 0, "Row 1: Col 2", 1, 1)
        _GUICtrlListView_AddSubItem($listview, 0, "Row 1: Col 3", 2, 2)
        _GUICtrlListView_AddItem($listview, "Row 2: Col 1", 1)
        _GUICtrlListView_AddSubItem($listview, 1, "Row 2: Col 2", 1, 2)
        _GUICtrlListView_AddItem($listview, "Row 3: Col 1", 2)
        _GUICtrlListView_AddItem($listview, "Row 4: Col 1", 3)
        _GUICtrlListView_AddItem($listview, "Row 5: Col 1", 4)
        _GUICtrlListView_AddSubItem($listview, 4, "Row 5: Col 2", 1, 3)
        _GUICtrlListView_AddItem($listview, "Row 6: Col 1", 5)
        _GUICtrlListView_AddSubItem($listview, 5, "Row 6: Col 2", 1, 4)
        _GUICtrlListView_AddSubItem($listview, 5, "Row 6: Col 3", 2, 3)

        ; Loop until user exits
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>_Main

[ 本帖最后由 himself 于 2008-9-7 22:15 编辑 ]

himself 发表于 2008-9-7 22:15:24

自己解决了,改了一下函数


Func _GUIImageList_AddIconA($hWnd, $sFile, $iIndex = 0, $fLarge = False)
        Local $tIcon, $iResult, $hIcon
       
        $tIcon = DllStructCreate("int Handle")
        If $fLarge Then
                $iResult = _WinAPI_ExtractIconEx($sFile, $iIndex, DllStructGetPtr($tIcon), 0, 1)
        Else
                $iResult = _WinAPI_ExtractIconEx($sFile, $iIndex, 0, DllStructGetPtr($tIcon), 1)
        EndIf
        ;_WinAPI_Check("_GUIImageList_AddIcon", ($iResult <= 0), -1)

        $hIcon = DllStructGetData($tIcon, "Handle")
        $iResult = _GUIImageList_ReplaceIcon($hWnd, -1, $hIcon)
        ;_WinAPI_Check("_GUIImageList_AddIcon", ($iResult = -1), -2)
        If $hIcon <> 0 Then _WinAPI_DestroyIcon($hIcon)
        Return $iResult
EndFunc   ;==>_GUIImageList_AddIcon

adang 发表于 2011-3-24 12:03:23

回复 2# himself


    谢谢楼主提示,我也正好遇到同样的问题
页: [1]
查看完整版本: _GUIImageList_AddIcon函数的一个BUG?