Sign in to follow this  
Followers 0
Gif

Toolbar Items

3 posts in this topic

#1 ·  Posted (edited)

Can i add custom icons (.ico) to my toolbar buttons using _GuiCtrl_Toolbar...() ?

If yes then how?

Edited by Gif

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Gif

Edit: This post belongs in (GUI) Help and Support.

you need to create a new 'ImageList' to replace the default Toolbar ImageList that uses fixed system icons.

you can't add icons to the default imagelist of icons you see in the helpfile examples so...

you need to replace the default ImageList with a custom one.

for each toolbar you can use the default ImageList (with system determined New/Save/Open buttons etc.) or your own.

you use the _GUICtrlToolbar_SetImageList command to replace the default ImageList.

Rebars are also good for organizing Toolbars and Controls

The helpfile has a great example script of rebar use for the _GUICtrlReBar_Create command in the GuiRebar Management section

Commands needed are in these helpfile sections

GuiImageList Management

GuiToolbar Management

GuiRebar Management

Script example needs AutoIt3 v3.2.10.0 or higher

(Modified from helpfile examples)

;AutoIt3 v3.2.10.0 or higher
;#AutoIt3Wrapper_Res_Icon_Add=C:\yourfolder\your.ico ; using compiler directives you can use icons without fileinstalling
#include <GuiConstantsEx.au3>
#include <GuiToolbar.au3>
#Include <GuiRebar.au3>
#Include <GuiImageList.au3>

Opt('MustDeclareVars', 1)
$Debug_TB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $iItem ; Command identifier of the button associated with the notification.
Global $hGUI, $hToolbar, $hReBar, $iMemo, $aStrings[5]
Global Enum $id1 = 1000, $id2, $id3, $id4, $id5 ; ID's for each ToolBar button

_Main()

Func _Main()

    Local $hToolBarImageListNorm, $hToolBarImageListDisabled, $hToolBarImageListHot, $aSize
    Local $style = BitOR($WS_CHILD, $WS_VISIBLE, $WS_BORDER, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $TBSTYLE_CUSTOMERASE)
    $hGUI = GUICreate("Toolbar", 400, 300)
    
    
    $hReBar = _GUICtrlReBar_Create ($hgui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS))
    $hToolbar = _GUICtrlToolbar_Create ($hGUI, $style)
    $aSize = _GUICtrlToolbar_GetMaxSize ($hToolbar)
    
    ; Add Icons from system DLL shell32.dll to ImageList
    $hToolBarImageListNorm = _GUIImageList_Create (16, 16, 5, 3)
    _GUIImageList_AddIcon ($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 110)
    _GUIImageList_AddIcon ($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 131)
    _GUIImageList_AddIcon ($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 165)
    _GUIImageList_AddIcon ($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 168)
    _GUIImageList_AddIcon ($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 137)
    _GUIImageList_AddIcon ($hToolBarImageListNorm, @SystemDir & "\shell32.dll", 146)
    
    ; add AutoIt icon from exe internal resources or icon added at compile time by compiler directives
    _GUIImageList_AddIcon ($hToolBarImageListNorm, @AutoItExe, 0) 
    _GUICtrlToolbar_SetImageList($hToolbar, $hToolBarImageListNorm)
    
    ; you can also add _GUICtrlToolbar_SetDisabledImageList and _GUICtrlToolbar_SetHotImageList
    ; for setting different icons for each state

    ; Add strings
    $aStrings[0] = _GUICtrlToolbar_AddString ($hToolbar, "&Open")
    $aStrings[1] = _GUICtrlToolbar_AddString ($hToolbar, "E&xit")
    $aStrings[2] = _GUICtrlToolbar_AddString ($hToolbar, "&Gear")
    $aStrings[3] = _GUICtrlToolbar_AddString ($hToolbar, "&Tunes")
    $aStrings[4] = _GUICtrlToolbar_AddString ($hToolbar, "&AutoIt")

    ; Add buttons
    _GUICtrlToolbar_AddButton ($hToolbar, $id1, 0, $aStrings[0])
    _GUICtrlToolbar_AddButton ($hToolbar, $id2, 1, $aStrings[1])
    _GUICtrlToolbar_AddButton ($hToolbar, $id3, 2, $aStrings[2])
    _GUICtrlToolbar_AddButtonSep ($hToolbar)
    _GUICtrlToolbar_AddButton ($hToolbar, $id4, 3, $aStrings[3])
    _GUICtrlToolbar_AddButtonSep ($hToolbar)
    _GUICtrlToolbar_AddButton ($hToolBar, $id5, 6, $aStrings[4]) ; use seventh icon in ImageList (AutoIt icon)
    
    _GUICtrlReBar_AddToolBarBand($hReBar, $hToolbar, "", 0)
    
    ; display number of icons in image list
    ;MsgBox(4096, "Information", "Image Count: " & _GUIImageList_GetImageCount($hToolBarImageListNorm)) 

    $iMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 20, 596, 396 - ($aSize[1] + 20), $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
    
    ; disable button 4 - greyed out appearance
    _GUICtrlToolbar_EnableButton($hToolbar, $id4, False)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   ;==>_Main


; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite


; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tNMHDR, $event, $hwndFrom, $code, $i_idNew, $dwFlags, $lResult, $idFrom, $i_idOld
    Local $tNMTOOLBAR, $tNMTBHOTITEM
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $idFrom = DllStructGetData($tNMHDR, "IDFrom")
    $code = DllStructGetData($tNMHDR, "Code")
    Switch $hwndFrom
        Case $hToolbar
            Switch $code
                Case $NM_LDOWN
                    ;------------------------------------------------------------------
                    MemoWrite("$NM_LDOWN: Clicked Item: " & $iItem & " at index: " & _
                    _GUICtrlToolbar_CommandToIndex ($hToolbar, $iItem))
                    ;------------------------------------------------------------------
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $i_idOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $i_idNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    $iItem = $i_idNew
                    $dwFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
                    If BitAND($dwFlags, $HICF_LEAVING) = $HICF_LEAVING Then
                        MemoWrite("$HICF_LEAVING: " & $i_idOld)
                    Else
                        Switch $i_idNew
                            Case $id1
                                ;------------------------------------
                                MemoWrite("$TBN_HOTITEMCHANGE: $id1")
                                ;------------------------------------
                            Case $id2
                                ;------------------------------------
                                MemoWrite("$TBN_HOTITEMCHANGE: $id2")
                                ;------------------------------------
                            Case $id3
                                ;------------------------------------
                                MemoWrite("$TBN_HOTITEMCHANGE: $id3")
                                ;------------------------------------
                            Case $id4
                                ;------------------------------------
                                MemoWrite("$TBN_HOTITEMCHANGE: $id4")
                                ;------------------------------------
                            Case $id5
                                ;------------------------------------
                                MemoWrite("$TBN_HOTITEMCHANGE: $id5")
                                ;------------------------------------
                        EndSwitch
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

thanks rover, i know about rebars and the default image list i just couldn't see a way of adding icons to a new, maybe because i was too impatient.. thanks again

Edited by Gif

Share this post


Link to post
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
Sign in to follow this  
Followers 0