Jump to content

Recommended Posts

Posted

I want to embed some icons into my AutoIT program then use them within the toolbar. However, the image list seems to not accept embedded icons that after compiling, the toolbar shows nothing. So what is the problem here :blink: ?

#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files\AutoIt3\Icons\filetype-blank.ico
#include <GuiToolbar.au3>
#include <GuiImageList.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
_Main()

Func _Main()
    Local $hGUI, $hToolbar, $hNormal
    $hGUI = GUICreate("Toolbar", 400, 300)
    $hToolbar = _GUICtrlToolbar_Create($hGUI)
    GUICtrlCreateIcon(@AutoItExe, -5, 40, 40, 16, 16) ;~    This works
    $hNormal = _GUIImageList_Create(16, 16)
;~  _GUIImageList_AddIcon($hNormal, @AutoItExe, -5) ;~  This doesn't work
    _GUIImageList_AddIcon($hNormal, "C:\Program Files\AutoIt3\Icons\filetype-blank.ico", 0) ;~  This works
    _GUICtrlToolbar_SetImageList($hToolbar, $hNormal)
    _GUICtrlToolbar_AddButton($hToolbar, 0, 0)
    GUISetState()
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc
Posted

An AutoIt exe has 4 icons, your script adds a fifth. The icons are 0-based, so normally there are 0 thru 3, you added index 4. This works fine:

#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files\AutoIt3\Icons\filetype-blank.ico
#include <GuiToolbar.au3>
#include <GuiImageList.au3>
#include <WinAPI.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
_Main()

Func _Main()
    Local $hGUI, $hToolbar, $hNormal, $iIconCnt, $iIconIndex
    $hGUI = GUICreate("Toolbar", 400, 300)
    $hToolbar = _GUICtrlToolbar_Create($hGUI)
    GUICtrlCreateIcon(@AutoItExe, -5, 100, 100, 16, 16) ;~    This works
    $iIconCnt = _WinAPI_ExtractIconEx(@AutoItExe, -1, 0, 0, 1) ; Get count
    MsgBox(64, "Debug", "Icon count in file = " & $iIconCnt)
    $hNormal = _GUIImageList_Create(16, 16)

    For $i = 0 To $iIconCnt - 1
        $iIconIndex = _GUIImageList_AddIcon($hNormal, @AutoItExe, $i)
    Next

    _GUICtrlToolbar_SetImageList($hToolbar, $hNormal)

    For $i = 0 To $iIconCnt
        _GUICtrlToolbar_AddButton($hToolbar, $i, $i)
    Next

    GUISetState()
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

Note the loop is 0 to $iIconCnt - 1.

:blink:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

Wow, that solved the problem :P but now I'm facing another problem : the toolbar doesn't show the transparency of the icons :blink:. Do you have any solution for this ;) ?

Posted Image

Posted
Thanks PsaltyDS & Yashied so much for your help!!! It's now all fine. Next time I will read the documentation more carefully :blink:

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
×
×
  • Create New...