Jump to content

Apply SetItemBmp to internal autoit trayitem


Go to solution Solved by Terenz,

Recommended Posts

Hello guys,

As title, i think is possible because i have found, casually, an example for apply a menu color usign a similiar way of the UDF _GUICtrlMenu* does

I have make some try but i don't know how to complete, some advice?

#include <WinAPI.au3>
#include <Constants.au3>
#include <GuiMenu.au3>
#NoTrayIcon

Opt("TrayMenuMode", 3)

;~ Global Const $MIM_APPLYTOSUBMENUS = 0x80000000
;~ Global Const $MIM_BACKGROUND = 0x00000002
;~ Global Const $MIIM_BITMAP = 0x00000080

$hGUI = GUICreate("")

TrayCreateItem("Item1")
TrayCreateItem("Item2")
TrayCreateItem("")
$ExitItem = TrayCreateItem("Exit")

TraySetState()

;~ SetMenuColor(0, 0xEEBB99) ; BGR color value, '0' means the tray context menu handle itself
SetItemBmp($ExitItem, _WinAPI_CreateSolidBitmap($hGUI, 0xFF0000, 11, 11))
_GUICtrlMenu_SetItemBmp(0, $ExitItem, _WinAPI_CreateSolidBitmap($hGUI, 0xFF0000, 11, 11))

While 1
    Local $Msg = TrayGetMsg()
    Switch $Msg
        Case $ExitItem
            Exit
    EndSwitch
WEnd

; Apply the color to the menu
Func SetMenuColor($nMenuID, $nColor)
    Local $hMenu = TrayItemGetHandle($nMenuID) ; Get the internal menu handle

    Local $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor)
    $hBrush = $hBrush[0]

    Local $stMenuInfo = DllStructCreate("dword;dword;dword;uint;ptr;dword;ptr")
    DllStructSetData($stMenuInfo, 1, DllStructGetSize($stMenuInfo))
    DllStructSetData($stMenuInfo, 2, BitOR($MIM_APPLYTOSUBMENUS, $MIM_BACKGROUND))
    DllStructSetData($stMenuInfo, 5, $hBrush)

    DllCall("user32.dll", "int", "SetMenuInfo", "hwnd", $hMenu, "ptr", DllStructGetPtr($stMenuInfo))
EndFunc   ;==>SetMenuColor

Func SetItemBmp($nItemID, $hBmp)
    Local $hMenu = TrayItemGetHandle($nItemID) ; Get the internal menu handle

    Local Const $tagMENUITEMINFO = "uint Size;uint Mask;uint Type;uint State;uint ID;handle SubMenu;handle BmpChecked;handle BmpUnchecked;" & _
        "ulong_ptr ItemData;ptr TypeData;uint CCH;handle BmpItem"
    Local $tInfo = DllStructCreate($tagMENUITEMINFO)
    DllStructSetData($tInfo, "Size", DllStructGetSize($tInfo))
    DllStructSetData($tInfo, "Mask", $MIIM_BITMAP)
    DllStructSetData($tInfo, "BmpItem", $hBmp)

    DllCall("User32.dll", "bool", "SetMenuItemInfoW", "handle", $hMenu, "uint", $nItemID, "bool", True, "struct*", $tInfo)
EndFunc   ;==>SetMenuColor

P.S. I don't want to use, if possible, the _GUICtrlMenu_CreatePopup because i don't like that way to manage item with WM_COMMAND, is more easy to use the internal one

Thanks

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

Also other functyion of that UDF can be applied to the native tray:

$hTray = TrayItemGetHandle(0) ;internal autoit tray menu handle
$iCount = DllCall("user32.dll", "int", "GetMenuItemCount", "handle", $hTray)
If Not @error Then ConsoleWrite("_GUICtrlMenu_GetItemCount: " & $iCount[0] & @CRLF)

But for $hBitmap i don't know how to solve. Dev? MVP? Users? :D

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

  • Solution

Why was moved? The question was related to the autoit "source" code and if was possible to apply that function, a question for "devs". Anyway i was right, is possible and my mistake was with the $iItem, you need to pass ONLY the position and NOT the ID or the handle of the tray item, after that SetItemBmp work right with the interal tray menu

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

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