Jump to content

Recommended Posts

Posted (edited)

Hi

_GUIImageList_AddIcon($hImagebtn3, $iconlist[$i][4],1, False)

When adding a icon to a imagelist or using it in any way you can use a default icon without risk of failure. However, if I want to use another icon in the exe (such as index 1) is there a way programatically to find out if it exists before I get the _GUIImageList_AddIcon: -1 error. Alternatively, is there away to suppress the error and thus give yourself the chance to try again with the default icon instead of crashing the script.

Appreciate the help

Picea

Edited by picea892
Posted

This, without quitting the program. Returns (-1) if error occurred.

Func __GUIImageList_AddIcon($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
    If $iResult <= 0 Then
        Return SetError(1, 0, -1)
    EndIf
    $hIcon = DllStructGetData($tIcon, "Handle")
    $iResult = _GUIImageList_ReplaceIcon($hWnd, -1, $hIcon)
    DllCall('user32.dll', 'int', 'DestroyIcon', 'ptr', $hIcon)
    If $iResult = -1 Then
        Return SetError(1, 0, -1)
    EndIf
    Return $iResult
EndFunc   ;==>__GUIImageList_AddIcon
Posted

Yashied that works like a charm. This is excellent!

Thanks again for your help. I wish one day to help you....I doubt I ever will be able.

I am certain there are others who have had this problem and never asked. At the very least by asking the question I have advanced the greater community.

Picea

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...