Jump to content

Set icon from dll to toolbar button


Recommended Posts

Hi,

As the title says, I can't get it to work. Here is the script :

#include <GUIConstantsEx.au3>
#include <GuiToolbar.au3>
#include <WinAPIConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GuiButton.au3>


Global $g_hToolbar, $g_idMemo, $aStrings[4]
Global $g_iItem ; Command identifier of the button associated with the notification.
Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave

Example()

Func Example()
    Local $hGUI, $aSize, $paSmall

    Local $tIconsSm = DllStructCreate("HANDLE[" & 1 & "]")
    Local $paSmall = DllStructGetPtr($tIconsSm)


    ; Create GUI
    $hGUI = GUICreate("Toolbar", 600, 400)
    $g_hToolbar = _GUICtrlToolbar_Create($hGUI)
    $aSize = _GUICtrlToolbar_GetMaxSize($g_hToolbar)

    $g_idMemo = GUICtrlCreateEdit("", 2, $aSize[1] + 40, 596, 396 - ($aSize[1] + 40), $WS_VSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    ; Add standard system bitmaps
;~     _GUICtrlToolbar_AddBitmap($g_hToolbar, 1, -1, $IDB_STD_SMALL_COLOR)

    ConsoleWrite("nb=" & _WinAPI_ExtractIconEx("shell32.dll", 215, 0, $paSmall, 1) & @CRLF) ; extinction
    ConsoleWrite("index=" & _GUICtrlToolbar_AddBitmap($g_hToolbar, 1, 0, DllStructGetData($tIconsSm, 1))&@CRLF)

    ConsoleWrite("nb=" & _WinAPI_ExtractIconEx("imageres.dll", 163, 0, $paSmall, 1) & @CRLF) ; reconnexion
    ConsoleWrite("index=" & _GUICtrlToolbar_AddBitmap($g_hToolbar, 1, 0, DllStructGetData($tIconsSm, 1))&@CRLF)

    ConsoleWrite("nb=" & _WinAPI_ExtractIconEx("shell32.dll", 238, 0, $paSmall, 1) & @CRLF) ; raffraichissement
    ConsoleWrite("index=" & _GUICtrlToolbar_AddBitmap($g_hToolbar, 1, 0, DllStructGetData($tIconsSm, 1))&@CRLF)


    ; Add buttons and text
    $aStrings[0] = _GUICtrlToolbar_AddString($g_hToolbar, "Extinction")
    $aStrings[1] = _GUICtrlToolbar_AddString($g_hToolbar, "Reconnection")
    $aStrings[2] = _GUICtrlToolbar_AddString($g_hToolbar, "Raffraichissement")

    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idNew, 0, $aStrings[0])
    _GUICtrlToolbar_AddButtonSep($g_hToolbar)
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idOpen, 1, $aStrings[1])
    _GUICtrlToolbar_AddButtonSep($g_hToolbar)
    _GUICtrlToolbar_AddButton($g_hToolbar, $e_idSave, 2, $aStrings[2])

;~ GUICtrlCreateButton("", 100,100,50,50,$BS_ICON)
;~ GUICtrlSendMsg(-1, $BM_SETIMAGE, $IMAGE_ICON, DllStructGetData($tIconsSm, 1))

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

    _WinAPI_DestroyIcon(DllStructGetData($tIconsSm, 1))

EndFunc   ;==>Example

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

; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $iMsgID, $wParam, $lParam)
    #forceref $hWndGUI, $iMsgID, $wParam
    Local $tNMHDR, $hWndFrom, $iCode, $iNew, $iFlags, $iOld
    Local $tNMTBHOTITEM
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $g_hToolbar
            Switch $iCode
                Case $NM_LDOWN
                    ;----------------------------------------------------------------------------------------------
                    MemoWrite("$NM_LDOWN: Clicked Item: " & $g_iItem & " at index: " & _GUICtrlToolbar_CommandToIndex($g_hToolbar, $g_iItem))
                    ;----------------------------------------------------------------------------------------------
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $iOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $iNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    $g_iItem = $iNew
                    $iFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
;~                     If BitAND($iFlags, $HICF_LEAVING) = $HICF_LEAVING Then
;~                         MemoWrite("$HICF_LEAVING: " & $iOld)
;~                     Else
;~                         Switch $iNew
;~                             Case $e_idNew
;~                                 ;----------------------------------------------------------------------------------------------
;~                                 MemoWrite("$TBN_HOTITEMCHANGE: $e_idNew")
;~                                 ;----------------------------------------------------------------------------------------------
;~                             Case $e_idOpen
;~                                 ;----------------------------------------------------------------------------------------------
;~                                 MemoWrite("$TBN_HOTITEMCHANGE: $e_idOpen")
;~                                 ;----------------------------------------------------------------------------------------------
;~                             Case $e_idSave
;~                                 ;----------------------------------------------------------------------------------------------
;~                                 MemoWrite("$TBN_HOTITEMCHANGE: $e_idSave")
;~                                 ;----------------------------------------------------------------------------------------------
;~                             Case $e_idHelp
;~                                 ;----------------------------------------------------------------------------------------------
;~                                 MemoWrite("$TBN_HOTITEMCHANGE: $idHelp")
;~                                 ;----------------------------------------------------------------------------------------------
;~                         EndSwitch
;~                     EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

It works if I use standard button.

 

Thanks for your time.

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...