Jump to content

Reading DLL Icons


perfaram
 Share

Recommended Posts

Hi all !

I'm trying to use some icons from a resource DLL that I created.

The icons will be used with the ITaskBarList UDF, as button icon and as overlay icon (like that :

post-82724-0-19181200-1392634768_thumb.p

BUT... I don't know how to do  >_<

I read a lot, but I can't find any working way to do it. Note that it works perfectly without DLL !

The SetOverlayIcon (included in ITaskBarList.au3) :

; #FUNCTION# ====================================================================================================
; Name...........:  _ITaskBar_SetOverlayIcon
; Description....:  Applies an overlay to a taskbar button to indicate application status or a notification to the user.
; Syntax.........:  _ITaskBar_SetOverlayIcon($hGui, $hIcon = 0, $sDescription = '')
; Parameters.....:  $hGui - Handle to Gui
;                   $hIcon - [Optional] - The handle of an icon to use as the overlay.
;                   $sDescription - [Optional] -  alt text version of the information conveyed by the overlay, for accessibility purposes.
; Return values..:  Success - 1
;                   Failure - 0 and sets @error to HRESULT error code or:
;                             1 - File Icon does not exist
;                             2 - Failed loading icon image.
; Author.........:  Brian J Christy (Beege)
; Remarks........:  The icon should be a small icon, measuring 16x16 pixels at 96 dpi. If the taskbar is configured
;                   through Taskbar and Start Menu Properties to show small icons, overlays cannot be applied and calls
;                   to this method are ignored
; ===============================================================================================================
Func _ITaskBar_SetOverlayIcon($hGui, $hIcon = 0, $sDescription = '')

    If $hIcon And Not IsPtr($hIcon) Then
        If Not FileExists($hIcon) Then Return SetError(1, 0, 0)
        If StringRight($hIcon, 3) = 'exe' Then
            $hIcon = __GetEXEIconHandle($hIcon)
            If @error Then Return SetError(2, 0, 0)
        Else
            $hIcon = _WinAPI_LoadImage(0, $hIcon, $IMAGE_ICON, 16, 16, $LR_LOADFROMFILE)
            If @error Then Return SetError(2, 0, 0)
        EndIf
    EndIf

    Local $iRet = $g_ITBL_oTaskBar.SetOverlayIcon($hGui, $hIcon, $sDescription)

    If IsPtr($hIcon) Then _WinAPI_DestroyIcon($hIcon)

    If $iRet Then Return SetError($iRet, 0, 0)
    Return 1

EndFunc   ;==>_ITaskBar_SetOverlayIcon

My code :

$ovicn1=_ResourceGetAsImage('TICO1', $RT_ICON, @ScriptDir & "\res\LOUP_data.dll")
_ITaskBar_SetOverlayIcon($maingui, $ovicn1)

I can use the other resources of the DLL, as translation files or PNG files.

Thanks in advance  :bye:

post-82724-0-19181200-1392634768_thumb.p

Never forget to mark a question as resolved, this button has been purposely created :-P 

Link to comment
Share on other sites

OK !

I added this func in ITaskBarList.au3 : 

Func __GetDLLIconHandle($sPath, $dIndex)
    Local $Icon = DllStructCreate("handle")
    $iIcon = _WinAPI_ExtractIconEx($sPath, $dIndex, 0, DllStructGetPtr($Icon), 1)
    If @error Then Return SetError(1, 0, 0)
    Return DllStructGetData($Icon, 1)
EndFunc   ;==>__GetEXEIconHandle

It extracts the icon at the specified index in a DLL, and returns the handle to it.

Then, replace the part beginning with 

If $hIcon <> -1 And Not IsPtr($hIcon) Then

In CreateButton and SetOverlayIcon by this :

If $hIcon <> -1 And Not IsPtr($hIcon) Then
        If Not FileExists($hIcon) Then Return SetError(1, 0, 0)
        If StringRight($hIcon, 3) = 'exe' Then
            $hIcon = __GetEXEIconHandle($hIcon)
            If @error Then Return SetError(2, 0, 0)
        ElseIf StringRight($hIcon, 3) = 'dll' Then
            $hIcon = __GetDLLIconHandle($hIcon, $dind)
            If @error Then Return SetError(2, 0, 0)
        Else
            $hIcon = _WinAPI_LoadImage(0, $hIcon, $IMAGE_ICON, 16, 16, $LR_LOADFROMFILE)
            If @error Then Return SetError(2, 0, 0)
        EndIf
    EndIf

Worked for me.

 

EDIT : Forgot to say that you must add a param to the CreateButton and SetOverlayIcon functions, named $dind.

Edited by perfaram

Never forget to mark a question as resolved, this button has been purposely created :-P 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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