Jump to content

[Solved] How to set a shell32.dll icon with _GUICtrlMenu_SetItemBmp()?


KaFu
 Share

Recommended Posts

Hiho Community,

I want to assign a shell32.dll icon to a menu entry. Code posted below returns a sucess, but icon won't show up. Anyone got a hint for me?

#include <GuiMenu.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>

Global $iMemo

_GDIPlus_Startup ()
_Main()
_GDIPlus_Shutdown()

Func _Main()
    Local $hGUI, $hFile, $hEdit, $hHelp, $hMain
    Local Enum $idNew = 1000, $idOpen, $idSave, $idExit, $idCut, $idCopy, $idPaste, $idAbout

    ; Create GUI
    $hGUI = GUICreate("Menu", 400, 300)

    ; Create File menu
    $hFile = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hFile, 0, "&New", $idNew)
    _GUICtrlMenu_InsertMenuItem ($hFile, 1, "&Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem ($hFile, 2, "&Save", $idSave)
    _GUICtrlMenu_InsertMenuItem ($hFile, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem ($hFile, 4, "E&xit", $idExit)

    ; Create Edit menu
    $hEdit = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hEdit, 0, "&Cut", $idCut)
    _GUICtrlMenu_InsertMenuItem ($hEdit, 1, "C&opy", $idCopy)
    _GUICtrlMenu_InsertMenuItem ($hEdit, 2, "&Paste", $idPaste)

    ; Create Help menu
    $hHelp = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hHelp, 0, "&About", $idAbout)

    ; Create Main menu
    $hMain = _GUICtrlMenu_CreateMenu ()
    _GUICtrlMenu_InsertMenuItem ($hMain, 0, "&File", 0, $hFile)
    _GUICtrlMenu_InsertMenuItem ($hMain, 1, "&Edit", 0, $hEdit)
    _GUICtrlMenu_InsertMenuItem ($hMain, 2, "&Help", 0, $hHelp)

    ; Set window menu
    _GUICtrlMenu_SetMenu ($hGUI, $hMain)

    ; Create memo control
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 276, 0)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Set New menu item to have a bitmap
    MsgBox(0,"",_GUICtrlMenu_SetItemBmp($hFile, 1, _GDIPlus_BitmapCreateFromHBITMAP(_WinAPI_SHExtractIcons('shell32.dll',8,16,16))))
    MemoWrite("Item bitmap handle: 0x" & Hex(_GUICtrlMenu_GetItemBmp ($hFile, 0)))

    ; 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



Func _WinAPI_SHExtractIcons($sIcon, $iIndex, $iWidth, $iHeight)

    Local $Ret = DllCall('shell32.dll', 'int', 'SHExtractIconsW', 'wstr', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr*', 0, 'ptr*', 0, 'int', 1, 'int', 0)

    If (@error) Or ($Ret[0] = 0) Or ($Ret[5] = Ptr(0)) Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[5]
EndFunc   ;==>_WinAPI_SHExtractIcons

Best Regards

Edited by KaFu
Link to comment
Share on other sites

With the new search at the forum, has cost very hard me to find this post. :)

The problem was not the search itself but using the right keywords ;) , thanks for your fast response, fully satisfies my need :) ...
Link to comment
Share on other sites

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